using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using FireStarter.Base;
using Firestarter.Test.Base;
using FireStarterModeller.BO;
using FireStarterModeller.BO.BusinessObjectRules;
using FireStarterModeller.Test.BO.Fakes;
using Habanero.Base;
using Habanero.Base.Exceptions;
using Habanero.BO;
using Habanero.BO.ClassDefinition;
using Habanero.Testability;
using Habanero.Util;
using NUnit.Framework;
using Rhino.Mocks;


namespace FireStarterModeller.Test.BO
{
    /// <summary>
    /// Provides a place to write custom tests for DMClass objects.
    /// This file is only written once and can be changed.  The Def file
    /// attached to this as a dependent is rewritten with each regeneration
    /// and contains the standard tests for DMClass.
    /// Regenerate this test project whenever there have been changes to the
    /// business objects.
    /// If tests are failing due to a unique setup in your application,
    /// you can either override the Create methods in TestUtils, or you
    /// can add the test to the ignore list below and reimplement it here.
    /// </summary>
    public partial class TestDMClass
    {


        [TestFixtureSetUp]
        public void SetupFixture()
        {
            TestUtilsDomain.SetupFixture();
        }

        [SetUp]
        public virtual void SetupTest()
        {
            //-------------------------------------------------------------------------------------
            // You can choose here whether to run against a database or whether to use an in-memory
            // database for all the tests, which runs quickly. It doesn't however check that
            // your database has the correct structure, which is partly the purpose of these tests.
            // The generated tests do already use an in-memory database where possible.
            // In your custom tests, you can set them to use an in-memory database by copying the
            // line to the first line of your test.
            //-------------------------------------------------------------------------------------
            //BORegistry.DataAccessor = new DataAccessorDB();
            TestUtilsDomain.SetupTest();
            BORegistry.DataAccessor = new DataAccessorInMemory();
        }




        [Test]
        public void Test_ToString()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedValidDMClass();

            TestUtilsDMClass.GetFactory()
                .WithMany(@class => @class.Properties)
                .WithOne(@class => @class.UniqueConstraints)
                .WithValue(@class => @class.SuperClass, new DMClass())
                .CreateValidBusinessObject();

            //---------------Assert Precondition----------------
            TestUtilsShared.AssertStringNotEmpty(dmClass.ClassNameBO, "dmClass.ClassNameBO");
            //---------------Execute Test ----------------------
            string actualToString = dmClass.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(dmClass.ClassNameBO, actualToString);
        }

        [Test]
        public void Test_ToString_ClassNameBOIsNull()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            dmClass.ClassNameBO = "";
            //---------------Assert Precondition----------------
            TestUtilsShared.AssertStringEmpty(dmClass.ClassNameBO, "dmClass.ClassNameBO");
            //---------------Execute Test ----------------------
            string actualToString = dmClass.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(dmClass.ClassID.ToString(), actualToString);
        }

        [Test]
        public void Test_ToString_LookupListIsNull_IDIsNull()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            dmClass.ClassNameBO = "";
            dmClass.ClassID = null;
            //---------------Assert Precondition----------------
            TestUtilsShared.AssertStringEmpty(dmClass.ClassNameBO, "dmClass.ClassNameBO");
            Assert.IsNull(dmClass.ClassID);
            //---------------Execute Test ----------------------
            string actualToString = dmClass.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual("-unnamed DMClass-", actualToString);
        }

        [Test]
        public void Test_Solution()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();

            //---------------Execute Test ----------------------
            var solution = dmClass.Solution;

            //---------------Test Result -----------------------
            Assert.AreSame(dmClass.Assembly.Solution, solution);
        }


        [Test]
        public void Test_GetClassName()
        {
            //---------------Set up test pack-------------------
            IModelClass modelClass = new DMClass();
            string className = TestUtilsShared.GetRandomString();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            ((DMClass) modelClass).ClassNameBO = className;
            //---------------Test Result -----------------------
            Assert.AreEqual(className, modelClass.ClassName);
        }

        [Test]
        public void Test_SetClassName()
        {
            //---------------Set up test pack-------------------
            IModelClass modelClass = new DMClass();
            string className = TestUtilsShared.GetRandomString();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            modelClass.ClassName = className;
            //---------------Test Result -----------------------
            Assert.AreEqual(className, ((DMClass) modelClass).ClassNameBO);
        }

        [Test]
        public void Test_GetProperties()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            DMProperty dmProperty1 = CreateDmProperty(dmClass);
            DMProperty dmProperty2 = CreateDmProperty(dmClass);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IList<IModelProperty> properties = ((IModelClass) dmClass).Properties;
            //---------------Test Result -----------------------
            Assert.AreEqual(2, properties.Count);
            Assert.IsTrue(properties.Contains(dmProperty1));
            Assert.IsTrue(properties.Contains(dmProperty2));
        }

 
        [Test]
        public void Test_AllProperties_ClonesObjectIdentity()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            DMProperty dmProperty1 = CreateDmProperty(dmClass);
            //DMProperty dmProperty2 = CreateDmProperty(dmClass);
            DMObjectIdentity objectIdentity = new DMObjectIdentity {IsObjectID = false};
            objectIdentity.Properties.Add(dmProperty1);
            dmClass.ObjectIdentity = objectIdentity;

            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmClass.ObjectIdentity);
            Assert.IsFalse(dmClass.ObjectIdentity.IsObjectID.GetValueOrDefault());
            Assert.AreEqual(dmProperty1.PropertyName, objectIdentity.Properties[0].PropertyName);
            //---------------Execute Test ----------------------
            IList<IModelProperty> allProperties = ((IModelClass) dmClass).AllProperties;
            //---------------Test Result -----------------------
            Assert.AreEqual(1, allProperties.Count);
            DMClass clonedClass = (DMClass) allProperties[0].Parent;
            Assert.IsNotNull(clonedClass.ObjectIdentity);
            Assert.AreSame(allProperties[0], clonedClass.ObjectIdentity.Properties[0]);
            Assert.AreEqual(dmProperty1.PropertyName, clonedClass.ObjectIdentity.Properties[0].PropertyName);
            Assert.IsFalse(clonedClass.ObjectIdentity.IsObjectID.GetValueOrDefault());
        }

        [Test] 
        public void Test_ModelClassAllProperties_ShouldReturnSameSetOfPropertiesIfCalledTwice()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            DMProperty dmProperty1 = CreateDmProperty(dmClass);
            DMObjectIdentity objectIdentity = new DMObjectIdentity { IsObjectID = false };
            objectIdentity.Properties.Add(dmProperty1);
            dmClass.ObjectIdentity = objectIdentity;
            //---------------Assert Precondition----------------
            
            //---------------Execute Test ----------------------
            IList<IModelProperty> allProperties = ((IModelClass)dmClass).AllProperties;
            IList<IModelProperty> secondCallToProps = ((IModelClass)dmClass).AllProperties;
            //---------------Test Result -----------------------
            Assert.AreEqual(allProperties, secondCallToProps);
            Assert.AreSame(allProperties.First(), secondCallToProps.First());
        }

#pragma warning disable 168
        [Test]
        public void Test_SetCloneClassToNull_ShouldClearClonedClass()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            CreateDmProperty(dmClass);
            IList<IModelProperty> properties = ((IModelClass)dmClass).AllProperties;//this line is needed 
             // to force the cloning.
            //---------------Assert Precondition----------------
            object clonedClass = ReflectionUtilities.GetPrivatePropertyValue(dmClass, "ClonedClass");
            Assert.IsNotNull(clonedClass);
            //---------------Execute Test ----------------------
            dmClass.ClearClonedClass();
            //---------------Test Result -----------------------
            object clonedClassAfterClear = ReflectionUtilities.GetPrivatePropertyValue(dmClass, "ClonedClass");
            Assert.IsNull(clonedClassAfterClear);
        }
#pragma warning restore 168

        [Test]
        public void Test_AllProperties_SuperClass_TwoLevel()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            DMProperty dmProperty1 = CreateDmProperty(dmClass);

            DMClass superClass = new DMClass();
            DMProperty dmProperty2 = CreateDmProperty(superClass);

            DMClass grandClass = new DMClass();
            DMProperty dmProperty3 = CreateDmProperty(grandClass);
            superClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship {SuperClass = grandClass};

            dmClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship {SuperClass = superClass};
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IList<IModelProperty> allProperties = ((IModelClass) dmClass).AllProperties;
            //---------------Test Result -----------------------
            Assert.AreEqual(3, allProperties.Count);
            Assert.AreNotSame(dmProperty1, allProperties[0]);
            Assert.AreNotSame(dmProperty2, allProperties[1]);
            Assert.AreNotSame(dmProperty3, allProperties[2]);

            Assert.AreEqual(dmProperty1.PropertyName, allProperties[0].PropertyName);
            Assert.AreEqual(dmProperty2.PropertyName, allProperties[1].PropertyName);
            Assert.AreEqual(dmProperty3.PropertyName, allProperties[2].PropertyName);

            Assert.AreEqual(dmClass.ClassNameBO, ((IModelClass) ((IModelProperty) dmProperty1).Parent).ClassName);
            Assert.AreEqual(dmClass.ClassNameBO, ((IModelClass) ((IModelProperty) dmProperty2).Parent).ClassName);
            Assert.AreEqual(dmClass.ClassNameBO, ((IModelClass) ((IModelProperty) dmProperty3).Parent).ClassName);
        }
        [Test]
        public void Test_AllProperties_SuperClass_TwoLevel_ShouldUseSubClassesClassName()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass {ClassNameBO = "SubClass"};
            DMProperty dmPropertySubClass = CreateDmProperty(dmClass);

            DMClass superClass = new DMClass {ClassNameBO = "SuperClass"};
            DMProperty dmPropertySuperClass = CreateDmProperty(superClass);

            DMClass superSuperClass = new DMClass {ClassNameBO = "SuperSuperClass"};
            DMProperty dmPropertySuperSuperClass = CreateDmProperty(superSuperClass);
            superClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship {SuperClass = superSuperClass};

            dmClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship {SuperClass = superClass};
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IList<IModelProperty> allProperties = ((IModelClass) dmClass).AllProperties;
            //---------------Test Result -----------------------
            IModelProperty clonedSubClassProp = allProperties.First(property => property.PropertyName == dmPropertySubClass.PropertyName);
            Assert.AreEqual(dmClass.ClassNameBO, ((IModelClass)clonedSubClassProp.Parent).ClassName);
            IModelProperty clonedSuperClassProp = allProperties.First(property => property.PropertyName == dmPropertySuperClass.PropertyName);
            Assert.AreEqual(dmClass.ClassNameBO, ((IModelClass)clonedSuperClassProp.Parent).ClassName);
            IModelProperty clonedSuperSuperClassProp = allProperties.First(property => property.PropertyName == dmPropertySuperSuperClass.PropertyName);
            Assert.AreEqual(dmClass.ClassNameBO, ((IModelClass)clonedSuperSuperClassProp.Parent).ClassName);
        }

        [Test]
        public void Test_CreateDMClass_FromClassesRelationship()
        {
            //---------------Set up test pack-------------------
            DMAssembly assembly = TestUtilsShared.CreateDMAssembly();
            DMClass dmClass = assembly.Classes.CreateBusinessObject();
            TestUtilsShared.UpdateBusinessObjectWithValidData(dmClass);
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty(dmClass);
            dmClass.CreateObjectIdentity(dmProperty);
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, assembly.Classes.CreatedBusinessObjects.Count);
            Assert.AreEqual(1, assembly.Classes.Count);
            //---------------Execute Test ----------------------
            dmClass.Save();
            //---------------Test Result -----------------------
            Assert.AreEqual(0, assembly.Classes.CreatedBusinessObjects.Count);
            Assert.AreEqual(1, assembly.Classes.Count);
        }

        [Test]
        public void Test_CreateDMClass()
        {
            //---------------Set up test pack-------------------
            DMAssembly assembly = TestUtilsShared.CreateDMAssembly();
            string className = TestUtilsShared.GetRandomString();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            DMClass dmClass = assembly.CreateClass(className);
            //---------------Test Result -----------------------
            Assert.IsNotNull(dmClass);
            Assert.AreEqual(className, dmClass.ClassNameBO);
            Assert.AreSame(assembly, dmClass.Assembly);
            Assert.Contains(dmClass, assembly.Classes.CreatedBusinessObjects);
        }

        [Test]
        public void Test_FindBOPropertyByColumnName_WhenPropertyExists_ShouldReturnProp()
        {
            //---------------Set up test pack-------------------
            string columnName = TestUtilsShared.GetRandomString();
            DMClass dmClass = new DMClass();
            DMProperty dmProperty1 = CreateDmProperty(dmClass);
            dmProperty1.MappedDBColumnName = columnName;
            DMProperty dmProperty2 = CreateDmProperty(dmClass);
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, dmClass.Properties.Count);
            Assert.IsTrue(dmClass.Properties.Contains(dmProperty1));
            Assert.IsTrue(dmClass.Properties.Contains(dmProperty2));
            //---------------Execute Test ----------------------
            DMProperty returnedDMProperty = dmClass.FindBOPropertyByColumnName(columnName);
            //---------------Test Result -----------------------
            Assert.AreSame(dmProperty1, returnedDMProperty);
        }

        [Test]
        public void Test_FindBOPropertyByColumnName_WhenPropertyDoesNotExist_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            string columnName = TestUtilsShared.GetRandomString();
            DMClass dmClass = new DMClass();
            DMProperty dmProperty1 = CreateDmProperty(dmClass);
            DMProperty dmProperty2 = CreateDmProperty(dmClass);
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, dmClass.Properties.Count);
            Assert.IsTrue(dmClass.Properties.Contains(dmProperty1));
            Assert.IsTrue(dmClass.Properties.Contains(dmProperty2));
            //---------------Execute Test ----------------------
            DMProperty returnedDMProperty = dmClass.FindBOPropertyByColumnName(columnName);
            //---------------Test Result -----------------------
            Assert.IsNull(returnedDMProperty);
        }

        [Test]
        public void Test_FindBOPropertyByColumnName_WhenDuplicatePropertyExists_ShouldReturnFirstByOrdinalPosition()
        {
            //---------------Set up test pack-------------------
            string columnName = TestUtilsShared.GetRandomString();
            DMClass dmClass = new DMClass();
            DMProperty dmProperty1 = CreateDmProperty(dmClass);
            dmProperty1.MappedDBColumnName = columnName;
            dmProperty1.OrdinalPosition = 3;
            DMProperty dmProperty2 = CreateDmProperty(dmClass);
            dmProperty2.MappedDBColumnName = columnName;
            dmProperty2.OrdinalPosition = 2;
            DMProperty dmProperty3 = CreateDmProperty(dmClass);
            //---------------Assert Precondition----------------
            Assert.AreEqual(3, dmClass.Properties.Count);
            Assert.IsTrue(dmClass.Properties.Contains(dmProperty1));
            Assert.IsTrue(dmClass.Properties.Contains(dmProperty2));
            Assert.IsTrue(dmClass.Properties.Contains(dmProperty3));
            //---------------Execute Test ----------------------
            DMProperty returnedDMProperty = dmClass.FindBOPropertyByColumnName(columnName);
            //---------------Test Result -----------------------
            Assert.AreSame(dmProperty2, returnedDMProperty);
        }

        [Test]
        public void Test_ClassNameBoProp_IsEditable_ShouldBeTrue_WhenNotGenerated()
        {
            //--------------- Set up test pack ------------------
            DMClass dmClass = new DMClass();
            //--------------- Test Preconditions ----------------
            Assert.IsFalse(dmClass.Generated.GetValueOrDefault());
            //--------------- Execute Test ----------------------
            IBOProp prop = dmClass.Props["ClassNameBO"];
            //--------------- Test Result -----------------------
            string message = "";
            Assert.AreEqual("", message);
            Assert.IsTrue(prop.IsEditable(out message));
        }

        [Test]
        public void Test_ClassNameBoProp_IsEditable_ShouldBeFalse_WhenGenerated()
        {
            //--------------- Set up test pack ------------------
            DMClass dmClass = new DMClass {Generated = true};
            //--------------- Test Preconditions ----------------
            Assert.IsTrue(dmClass.Generated.GetValueOrDefault());
            //--------------- Execute Test ----------------------
            IBOProp prop = dmClass.Props["ClassNameBO"];
            //--------------- Test Result -----------------------
            string message;
            Assert.IsFalse(prop.IsEditable(out message));
        }

        [Test]
        public void Test_IsDeletable_ShouldBeFalse_WhenGenerated()
        {
            //--------------- Set up test pack ------------------
            DMClass dmClass = new DMClass {Generated = true};
            //--------------- Test Preconditions ----------------
            Assert.IsTrue(dmClass.Generated.GetValueOrDefault());
            //--------------- Execute Test ----------------------
            string message;
            bool isDeletable = dmClass.IsDeletable(out message);
            //--------------- Test Result -----------------------
            Assert.IsFalse(isDeletable);
            StringAssert.Contains(
                "The entity '" + dmClass.ToString() + "' cannot be deleted as it has already been exported.", message);
        }

        [Test]
        public void Test_IsDeletable_ShouldBeTrue_WhenNotGenerated()
        {
            //--------------- Set up test pack ------------------
            DMClass dmClass = new DMClass();

            //--------------- Test Preconditions ----------------
            Assert.IsFalse(dmClass.Generated.GetValueOrDefault());
            //--------------- Execute Test ----------------------
            string message;
            bool isDeletable = dmClass.IsDeletable(out message);
            //--------------- Test Result -----------------------
            Assert.IsTrue(isDeletable);
            Assert.AreEqual("", message);
        }

        [Test]
        public void Test_GetNonSingleRelationshipProperties_WithNoOwnerRelationships_ShouldReturnAllProperties()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClassWithProps();
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, dmClass.Properties.Count);
            Assert.AreEqual(0, dmClass.OwnerRelationships.Count);
            //---------------Execute Test ----------------------
            BusinessObjectCollection<DMProperty> nonSingleRelationshipProperties =
                dmClass.GetNonSingleRelationshipProperties();
            //---------------Test Result -----------------------
            Assert.AreEqual(2, nonSingleRelationshipProperties.Count);
        }

        [Test]
        public void Test_GetNonSingleRelationshipProperties_WithOwnerRelationship()
        {
            //---------------Set up test pack-------------------
            DMSolution solution = TestUtilsDMSolution.CreateSavedDMSolutionWithTwoClasses();
            DMClass ownerClass = solution.AllClasses[0];
            DMClass relatedClass = solution.AllClasses[1];
            DMProperty ownerProperty = TestUtilsDMProperty.CreateUnsavedValidDMProperty(ownerClass);
            DMProperty property2 = TestUtilsDMProperty.CreateUnsavedValidDMProperty(ownerClass);
            DMProperty relatedProperty = TestUtilsDMProperty.CreateUnsavedValidDMProperty(relatedClass);
            DMRelationship relationship = ownerClass.OwnerRelationships.CreateBusinessObject();
            relationship.Cardinality = Cardinality.Single;
            relationship.RelatedClass = relatedClass;
            DMRelationshipProperty relationshipProperty = relationship.RelationshipProperties.CreateBusinessObject();
            relationshipProperty.OwnerProperty = ownerProperty;
            relationshipProperty.RelatedProperty = relatedProperty;
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, ownerClass.Properties.Count);
            Assert.AreEqual(1, ownerClass.OwnerRelationships.Count);
            //---------------Execute Test ----------------------
            BusinessObjectCollection<DMProperty> nonSingleRelationshipProperties =
                ownerClass.GetNonSingleRelationshipProperties();
            //---------------Test Result -----------------------
            Assert.AreEqual(1, nonSingleRelationshipProperties.Count);
            Assert.IsFalse(nonSingleRelationshipProperties.Contains(ownerProperty));
            Assert.IsTrue(nonSingleRelationshipProperties.Contains(property2));
        }

        [Test]
        public void Test_AllProperties_EmptyCollection()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            BusinessObjectCollection<DMProperty> properties = dmClass.AllProperties;
            //---------------Test Result -----------------------
            Assert.IsNotNull(properties);
            Assert.AreEqual(0, properties.Count);
        }


        [Test]
        public void Test_AllProperties_WithNoSuperClass()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            DMProperty dmProperty1 = CreateDmProperty(dmClass);
            DMProperty dmProperty2 = CreateDmProperty(dmClass);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            BusinessObjectCollection<DMProperty> allProperties = dmClass.AllProperties;
            //---------------Test Result -----------------------
            Assert.AreEqual(2, allProperties.Count);
            Assert.AreEqual(dmProperty1.PropertyName, allProperties[0].PropertyName);
            Assert.AreEqual(dmProperty2.PropertyName, allProperties[1].PropertyName);
        }

        [Test]
        public void Test_AllProperties_WithSuperClass_OneLevel()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            DMProperty dmProperty1 = CreateDmProperty(dmClass);
            DMProperty dmProperty2 = CreateDmProperty(dmClass);

            DMClass superClass = new DMClass();
            DMProperty dmProperty3 = CreateDmProperty(superClass);
            DMProperty dmProperty4 = CreateDmProperty(superClass);
            dmClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship {SuperClass = superClass};
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            BusinessObjectCollection<DMProperty> allProperties = dmClass.AllProperties;
            //---------------Test Result -----------------------
            Assert.AreEqual(4, allProperties.Count);
            Assert.AreSame(dmProperty1, allProperties[0]);
            Assert.AreSame(dmProperty2, allProperties[1]);
            Assert.AreSame(dmProperty3, allProperties[2]);
            Assert.AreSame(dmProperty4, allProperties[3]);
        }


        [Test]
        public void Test_AllProperties_WithSuperClass_TwoLevel()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            DMProperty dmProperty1 = CreateDmProperty(dmClass);

            DMClass superClass = new DMClass();
            DMProperty dmProperty2 = CreateDmProperty(superClass);

            DMClass grandClass = new DMClass();
            DMProperty dmProperty3 = CreateDmProperty(grandClass);
            superClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship {SuperClass = grandClass};

            dmClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship {SuperClass = superClass};
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            BusinessObjectCollection<DMProperty> allProperties = dmClass.AllProperties;
            //---------------Test Result -----------------------
            Assert.AreEqual(3, allProperties.Count);
            Assert.AreSame(dmProperty1, allProperties[0]);
            Assert.AreSame(dmProperty2, allProperties[1]);
            Assert.AreSame(dmProperty3, allProperties[2]);
        }

        [Test]
        public void Test_FindDMProperty_WhenHasOne_ShouldReturnDMProp()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            DMProperty dmProperty1 = CreateDmProperty(dmClass);
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, dmClass.Properties.Count);
            //---------------Execute Test ----------------------
            DMProperty foundProp = dmClass.FindPropByName(dmProperty1.PropertyName);
            //---------------Test Result -----------------------
            Assert.AreSame(dmProperty1, foundProp);
        }

        [Test]
        public void Test_FindDMProperty_WhenDoesNotMatch_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            CreateDmProperty(dmClass);
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, dmClass.Properties.Count);
            //---------------Execute Test ----------------------
            DMProperty foundProp = dmClass.FindPropByName("someOtherName");
            //---------------Test Result -----------------------
            Assert.IsNull(foundProp);
        }

        [Test]
        public void Test_GetObjectID_WhenDMClassHasNoObjectID_ShouldBeNull()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateSavedDMClass();
            //---------------Assert Precondition----------------
            Assert.IsNull(dmClass.ObjectIdentity);
            //---------------Execute Test ----------------------
            DMObjectIdentity objectIdentity = dmClass.GetObjectID();
            //---------------Test Result -----------------------
            Assert.IsNull(objectIdentity);
        }

        [Test]
        public void Test_GetObjectID_WhenDMClassHasObjectID_ShouldNotBeNull()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateSavedDMClass();
            DMObjectIdentity savedDmObjectIdentity = TestUtilsDMObjectIdentity.CreateSavedDMObjectIdentity(dmClass);

            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmClass.ObjectIdentity);
            //---------------Execute Test ----------------------
            DMObjectIdentity objectIdentity = dmClass.GetObjectID();
            //---------------Test Result -----------------------
            Assert.IsNotNull(objectIdentity);
            Assert.AreSame(savedDmObjectIdentity, objectIdentity);
        }

        [Test]
        public void Test_GetObjectID_WhenObjectIDInOwnerSuperClass_ShouldBeSuperClassesObjectID()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship inheritanceRelationship =
                TestUtilsDMInheritanceRelationship.CreateSavedDMInheritanceRelationship();
            DMClass superClass = inheritanceRelationship.SuperClass;
            superClass.ObjectIdentity = TestUtilsDMObjectIdentity.CreateSavedDMObjectIdentity(superClass);
            DMClass subClass = inheritanceRelationship.SubClass;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(superClass.ObjectIdentity);
            Assert.IsNull(subClass.ObjectIdentity);
            //---------------Execute Test ----------------------
            DMObjectIdentity objectIdentity = subClass.GetObjectID();
            //---------------Test Result -----------------------
            Assert.IsNotNull(objectIdentity);
            Assert.AreSame(superClass.ObjectIdentity, objectIdentity);
        }


        [Test]
        public void Test_GetObjectID_WhenObjectIDInOwnerSuperSuperClass_ShouldBeSuperSuperClassObjectID()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship inheritanceRelationship =
                TestUtilsDMInheritanceRelationship.CreateSavedDMInheritanceRelationship();
            DMClass superSuper = inheritanceRelationship.SuperClass;
            superSuper.ObjectIdentity = TestUtilsDMObjectIdentity.CreateSavedDMObjectIdentity(superSuper);
            DMClass superClass = inheritanceRelationship.SubClass;

            DMInheritanceRelationship secondInheritance =
                TestUtilsDMInheritanceRelationship.CreateUnsavedValidDMInheritanceRelationship();
            secondInheritance.SuperClass = superClass;
            DMClass subClass = secondInheritance.SubClass;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(superSuper.ObjectIdentity);
            Assert.AreEqual(1, superSuper.ObjectIdentity.Properties.Count);
            Assert.IsNull(superClass.ObjectIdentity);
            Assert.IsNull(subClass.ObjectIdentity);
            //---------------Execute Test ----------------------
            DMObjectIdentity objectIdentity = subClass.GetObjectID();
            //---------------Test Result -----------------------
            Assert.IsNotNull(objectIdentity);
            Assert.AreSame(superSuper.ObjectIdentity, objectIdentity);
        }

        [Test]
        public void Test_IsObjectIDValid_WhenHasObjectIDWithOneProp_ShouldBeTrue()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateSavedDMClass();
            TestUtilsDMObjectIdentity.CreateSavedDMObjectIdentity(dmClass);
            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmClass.ObjectIdentity);
            Assert.AreEqual(1, dmClass.ObjectIdentity.Properties.Count);
            //---------------Execute Test ----------------------
            bool testIsObjectIDValid = dmClass.IsObjectIDValid;
            //---------------Test Result -----------------------
            Assert.IsTrue(testIsObjectIDValid);
        }

        [Test]
        public void Test_IsObjectIDValid_WhenNoObjectID_ShouldBeFalse()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            //---------------Assert Precondition----------------
            Assert.IsNull(dmClass.ObjectIdentity);
            //---------------Execute Test ----------------------
            bool testIsObjectIDValid = dmClass.IsObjectIDValid;
            //---------------Test Result -----------------------
            Assert.IsFalse(testIsObjectIDValid);
        }

        [Test]
        public void Test_IsObjectIDValid_WhenObjectIDWithNoProps_ShouldBeFalse()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateSavedDMClass();
            DMObjectIdentity objectIdentity = TestUtilsDMObjectIdentity.CreateUnsavedValidDMObjectIdentity_NoDMClass();
            objectIdentity.Class = dmClass;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmClass.ObjectIdentity);
            Assert.AreEqual(0, dmClass.ObjectIdentity.Properties.Count);
            //---------------Execute Test ----------------------
            bool testIsObjectIDValid = dmClass.IsObjectIDValid;
            //---------------Test Result -----------------------
            Assert.IsFalse(testIsObjectIDValid);
        }

        [Test]
        public void Test_IsObjectIDValid_WhenObjectIDInSuperClass_ShouldBeTrue()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship inheritanceRelationship =
                TestUtilsDMInheritanceRelationship.CreateSavedDMInheritanceRelationship();
            DMClass superClass = inheritanceRelationship.SuperClass;
            superClass.ObjectIdentity = TestUtilsDMObjectIdentity.CreateSavedDMObjectIdentity(superClass);
            DMClass subClass = inheritanceRelationship.SubClass;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(superClass.ObjectIdentity);
            Assert.AreEqual(1, superClass.ObjectIdentity.Properties.Count);
            Assert.IsNull(subClass.ObjectIdentity);
            //---------------Execute Test ----------------------
            bool testIsObjectIDValid = subClass.IsObjectIDValid;
            //---------------Test Result -----------------------
            Assert.IsTrue(testIsObjectIDValid);
        }

        [Test]
        public void Test_IsObjectIDValid_WhenObjectIDInSuperSuperClass_ShouldBeTrue()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship inheritanceRelationship =
                TestUtilsDMInheritanceRelationship.CreateSavedDMInheritanceRelationship();
            DMClass superSuper = inheritanceRelationship.SuperClass;
            superSuper.ObjectIdentity = TestUtilsDMObjectIdentity.CreateSavedDMObjectIdentity(superSuper);
            DMClass superClass = inheritanceRelationship.SubClass;

            DMInheritanceRelationship secondInheritance =
                TestUtilsDMInheritanceRelationship.CreateUnsavedValidDMInheritanceRelationship();
            secondInheritance.SuperClass = superClass;
            DMClass subClass = secondInheritance.SubClass;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(superSuper.ObjectIdentity);
            Assert.AreEqual(1, superSuper.ObjectIdentity.Properties.Count);
            Assert.IsNull(superClass.ObjectIdentity);
            Assert.IsNull(subClass.ObjectIdentity);
            //---------------Execute Test ----------------------
            bool testIsObjectIDValid = subClass.IsObjectIDValid;
            //---------------Test Result -----------------------
            Assert.IsTrue(testIsObjectIDValid);
        }

        [Test]
        public void Test_PrimaryKeyDef_WhenDMClassHasNoObjectID_ShouldBeNull()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateSavedDMClass();
            IClassDef classAsDef = dmClass;
            //---------------Assert Precondition----------------
            Assert.IsNull(dmClass.ObjectIdentity);
            //---------------Execute Test ----------------------
            var objectIdentity = classAsDef.PrimaryKeyDef;
            //---------------Test Result -----------------------
            Assert.IsNull(objectIdentity);
        }

        [Test]
        public void Test_PrimaryKeyDef_WhenDMClassHasObjectID_ShouldNotBeNull()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateSavedDMClass();
            DMObjectIdentity savedDmObjectIdentity = TestUtilsDMObjectIdentity.CreateSavedDMObjectIdentity(dmClass);
            IClassDef classAsDef = dmClass;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmClass.ObjectIdentity);
            //---------------Execute Test ----------------------
            var objectIdentity = classAsDef.PrimaryKeyDef;
            //---------------Test Result -----------------------
            Assert.IsNotNull(objectIdentity);
            Assert.AreSame(savedDmObjectIdentity, objectIdentity);
        }

        [Test]
        public void Test_PrimaryKeyDef_WhenObjectIDInSuperClass_ShouldBeNull()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship inheritanceRelationship =
                TestUtilsDMInheritanceRelationship.CreateSavedDMInheritanceRelationship();
            DMClass superClass = inheritanceRelationship.SuperClass;
            superClass.ObjectIdentity = TestUtilsDMObjectIdentity.CreateSavedDMObjectIdentity(superClass);
            IClassDef subClass = inheritanceRelationship.SubClass;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(superClass.ObjectIdentity);
            Assert.IsNull(((DMClass) subClass).ObjectIdentity);
            //---------------Execute Test ----------------------
            var objectIdentity = subClass.PrimaryKeyDef;
            //---------------Test Result -----------------------
            Assert.IsNull(objectIdentity);
        }

        //[Test]
        //public void Test_DeleteClass_ShouldDeleteProperties()
        //{
        //    //--------------- Set up test pack ------------------
        //    string sourceFile = @"C:\systems\Habanero Tools\FireStarter_Modeller\trunk\source\FireStarterModeller\bin\Debug\SerialiseData\FireStarterModeller.db4o";
        //    Db4oFactory.Configure().ObjectClass(typeof(BusinessObjectDTO)).CascadeOnUpdate(true);
        //    DB4ORegistry.DB = Db4oFactory.OpenFile(sourceFile);
        //    BORegistry.DataAccessor = new DataAccessorDB4O(DB4ORegistry.DB);
        //    DMClass dmClass = TestUtilsShared.CreateSavedDMClassWithProps();
        //    BusinessObjectCollection<DMProperty> properties = dmClass.Properties;
        //    DMProperty property1 = properties[0];
        //    DMProperty property2 = properties[1];
        //    //--------------- Test Preconditions ----------------
        //    Assert.IsFalse(dmClass.Status.IsDeleted);
        //    Assert.IsFalse(property1.Status.IsDeleted);
        //    Assert.IsFalse(property2.Status.IsDeleted);
        //    //--------------- Execute Test ----------------------
        //    //for (int counter = properties.Count -1; counter >=0  ; counter--)
        //    //{
        //    //    DMProperty property = properties[counter];
        //    //    property.MarkForDelete();
        //    //    property.Save();
        //    //}
        //    dmClass.MarkForDelete();
        //    dmClass.Save();
        //    //--------------- Test Result -----------------------
        //    Assert.IsTrue(dmClass.Status.IsDeleted);
        //    Assert.AreEqual(0 ,dmClass.Properties.Count);
        //    Assert.IsTrue(property1.Status.IsDeleted);
        //    Assert.IsTrue(property2.Status.IsDeleted);
        //}

        //[Test]
        //public void Test_SaveDmClass_RaisesError_WhenNoObjectIdentity()
        //{
        //    //--------------- Set up test pack ------------------
        //    DMClass dmClass = TestUtilsShared.CreateUnsavedValidDMClass();
        //    //--------------- Test Preconditions ----------------
        //    Assert.IsNull(dmClass.ObjectIdentity);
        //    //--------------- Execute Test ----------------------
        //    try
        //    {
        //        dmClass.Save();
        //        Assert.Fail("expected Err");
        //    }
        //    //---------------Test Result -----------------------
        //    catch (BusObjectInAnInvalidStateException ex)
        //    {
        //        StringAssert.Contains("The Entity '" + dmClass.ToString() + "' cannot be saved as there is no primary key set for this entity.", ex.Message);
        //    }            
        //}

        #region Move DMProps

        private static void AssertPropsAreInOrder(DMProperty prop1, DMProperty prop2, DMProperty prop3)
        {
            Assert.AreEqual(1, prop1.OrdinalPosition, "First Prop should be in position 1");
            Assert.AreEqual(2, prop2.OrdinalPosition, "Second Prop should be in position 2");
            Assert.AreEqual(3, prop3.OrdinalPosition, "Third Prop should be in position 2");
        }

        [Test]
        public void Test_CreateProperty_ShouldAddToEndOfPropertiesCollection()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = TestUtilsShared.CreateSavedDMClassWithProps();
            BusinessObjectCollection<DMProperty> properties = dmClass.Properties;

            //---------------Assert Preconditions --------------
            Assert.AreEqual(2, properties.Count);
            //---------------Execute Test ----------------------
            DMProperty prop3 = properties.CreateBusinessObject();
            //---------------Test Result ----------------------
            Assert.AreSame(prop3, properties[2]);
        }


        [Test]
        public void TestAcceptance_UC8_MoveDMPropertyUp()
        {
            //---------------Set up test pack-------------------
            //ClearAssetTables();
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedDefaultDMClass();
            DMProperty prop1 = dmClass.Properties.CreateBusinessObject();
            DMProperty prop2 = dmClass.Properties.CreateBusinessObject();
            DMProperty prop3 = dmClass.Properties.CreateBusinessObject();
            //---------------Assert Preconditions --------------
            AssertPropsAreInOrder(prop1, prop2, prop3);
            //---------------Execute Test ----------------------
            dmClass.MovePropertyUp(prop3);
            //---------------Test Result -----------------------
            AssertPropsAreInOrder(prop1, prop3, prop2);
        }

        [Test]
        public void TestAcceptance_UC8_MoveDMPropertyDown()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedDefaultDMClass();
            DMProperty prop1 = dmClass.Properties.CreateBusinessObject();
            DMProperty prop2 = dmClass.Properties.CreateBusinessObject();
            DMProperty prop3 = dmClass.Properties.CreateBusinessObject();
            //---------------Execute Test ----------------------
            dmClass.MovePropertyDown(prop1);
            //---------------Test Result -----------------------
            AssertPropsAreInOrder(prop2, prop1, prop3);
        }

        //[Test]
        //public void TestAcceptance_UC8_MoveDMPropertyDown_SavedProp()
        //{
        //    //---------------Set up test pack-------------------
        //                    //Customised so as to save the state of all the business objects to an appropriate file.
        //    string db4oDataFile = Path.Combine(@"C:\", "FireStarterModeller.db4o");
        //    Db4oFactory.Configure().ObjectClass(typeof(BusinessObjectDTO)).CascadeOnUpdate(true);
        //    DB4ORegistry.DB = Db4oFactory.OpenFile(db4oDataFile);
        //    BORegistry.DataAccessor = new DataAccessorDB4O(DB4ORegistry.DB);
        //    DMClass dmClass = TestUtilsDMClass.CreateSavedDMClass();
        //    DMProperty prop1 = dmClass.Properties.CreateBusinessObject();

        //    DMProperty prop2 = dmClass.Properties.CreateBusinessObject();
        //    DMProperty prop3 = dmClass.Properties.CreateBusinessObject();
        //    TestUtilsShared.UpdateDMPropertyWithValidData(prop1);
        //    TestUtilsShared.UpdateDMPropertyWithValidData(prop2);
        //    TestUtilsShared.UpdateDMPropertyWithValidData(prop3);
        //    dmClass.Save();
        //    BusinessObjectManager.Instance.ClearLoadedObjects();
        //    dmClass.Properties.Refresh();
        //    dmClass.Properties.Sort("OrdinalPosition", true, true);
        //    DMProperty loadedProperty1 = dmClass.Properties[0];
        //    DMProperty loadedProperty2 = dmClass.Properties[1];
        //    DMProperty loadedProperty3 = dmClass.Properties[2];
        //    //----------------Assert Precondition --------------
        //    Assert.IsFalse(loadedProperty1.Status.IsNew);
        //    Assert.AreNotSame(loadedProperty1, prop1);
        //    Assert.AreEqual(loadedProperty1.PropertyName, prop1.PropertyName);
        //    //---------------Execute Test ----------------------
        //    dmClass.MovePropertyDown(loadedProperty1);
        //    dmClass.MovePropertyDown(loadedProperty1);
        //    dmClass.MovePropertyDown(loadedProperty1);
        //    //---------------Test Result -----------------------
        //    AssertPropsAreInOrder(loadedProperty2, loadedProperty3, loadedProperty1);
        //}

        [Test]
        public void TestAcceptance_UC8_MoveDMPropertyDown_ReordersDMPropertyRelationshipCollection()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedDefaultDMClass();
            DMProperty prop1 = dmClass.Properties.CreateBusinessObject();
            DMProperty prop2 = dmClass.Properties.CreateBusinessObject();
            DMProperty prop3 = dmClass.Properties.CreateBusinessObject();
            //---------------Execute Test ----------------------
            dmClass.MovePropertyDown(prop1);
            BusinessObjectCollection<DMProperty> props = dmClass.Properties;
            props.Sort("OrdinalPosition", true, true);
            //---------------Test Result -----------------------
            Assert.AreSame(prop2, props[0]);
            Assert.AreSame(prop1, props[1]);
            Assert.AreSame(prop3, props[2]);
        }

        [Test]
        public void Test_MoveDMPropertyDown_PropNull_DoesNothing()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedDefaultDMClass();
            DMProperty prop1 = dmClass.Properties.CreateBusinessObject();
            DMProperty prop2 = dmClass.Properties.CreateBusinessObject();
            DMProperty prop3 = dmClass.Properties.CreateBusinessObject();
            //---------------Execute Test ----------------------
            dmClass.MovePropertyDown(null);
            BusinessObjectCollection<DMProperty> props = dmClass.Properties;
            props.Sort("OrdinalPosition", true, true);
            //---------------Test Result -----------------------
            Assert.AreSame(prop1, props[0]);
            Assert.AreSame(prop2, props[1]);
            Assert.AreSame(prop3, props[2]);
        }

        [Test]
        public void Test_MoveDMPropertyUp_PropNull_DoesNothing()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedDefaultDMClass();
            DMProperty prop1 = dmClass.Properties.CreateBusinessObject();
            DMProperty prop2 = dmClass.Properties.CreateBusinessObject();
            DMProperty prop3 = dmClass.Properties.CreateBusinessObject();
            //---------------Execute Test ----------------------
            dmClass.MovePropertyUp(null);
            BusinessObjectCollection<DMProperty> props = dmClass.Properties;
            props.Sort("OrdinalPosition", true, true);
            //---------------Test Result -----------------------
            Assert.AreSame(prop1, props[0]);
            Assert.AreSame(prop2, props[1]);
            Assert.AreSame(prop3, props[2]);
        }

        [Test]
        public void TestCreateDMProperty()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedDefaultDMClass();
            //---------------Execute Test ----------------------
            DMProperty dmProp = dmClass.CreateDMProp();
            //---------------Test Result -----------------------
            Assert.AreSame(dmClass, dmProp.Class);
            Assert.AreEqual(1, dmProp.OrdinalPosition);
        }

        [Test]
        public void TestCreateDMPropertyOrdinalPosition()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedDefaultDMClass();
            //---------------Execute Test ----------------------
            DMProperty dmProp1 = dmClass.CreateDMProp();
            DMProperty dmProp2 = dmClass.CreateDMProp();
            //---------------Test Result -----------------------
            Assert.AreEqual(1, dmProp1.OrdinalPosition);
            Assert.AreEqual(2, dmProp2.OrdinalPosition);
        }

        [Test]
        public void TestCreateDMPropertyOrdinalPosition_SaveAndAddOne_ShouldHaveNextNumber()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            DMProperty dmProp1 = TestUtilsDMProperty.SetDMPropTOValidValues(dmClass.CreateDMProp());
            DMProperty dmProp2 = TestUtilsDMProperty.SetDMPropTOValidValues(dmClass.CreateDMProp());
            dmClass.CreateObjectIdentity(dmProp1);
            dmClass.Save();
            //---------------Assert Preconditions--------------
            Assert.AreEqual(1, dmProp1.OrdinalPosition);
            Assert.AreEqual(2, dmProp2.OrdinalPosition);
            Assert.IsFalse(dmProp2.Status.IsNew);
            //---------------Execute Test ----------------------
            DMProperty dmProp3 = dmClass.CreateDMProp();
            //---------------Test Result -----------------------
            Assert.AreEqual(3, dmProp3.OrdinalPosition);
            Assert.IsTrue(dmProp3.Status.IsNew);
        }

        [Test]
        public void TestCreateDMPropertyOrdinalPosition_SaveAndDeleteFirstAddOne_ShouldHaveNextNumber()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            DMProperty dmProp1 = TestUtilsDMProperty.SetDMPropTOValidValues(dmClass.CreateDMProp());
            DMProperty dmProp2 = TestUtilsDMProperty.SetDMPropTOValidValues(dmClass.CreateDMProp());
            dmClass.CreateObjectIdentity(dmProp2);
            dmClass.Save();
            //---------------Assert Preconditions--------------
            Assert.AreEqual(1, dmProp1.OrdinalPosition);
            Assert.AreEqual(2, dmProp2.OrdinalPosition);
            Assert.IsFalse(dmProp2.Status.IsNew);
            //---------------Execute Test ----------------------
            dmProp1.MarkForDelete();
            DMProperty dmProp3 = dmClass.CreateDMProp();
            //---------------Test Result -----------------------
            Assert.AreEqual(3, dmProp3.OrdinalPosition);
            Assert.IsTrue(dmProp3.Status.IsNew);
        }


        [Test]
        public void TestCreate_Serialise_Desrialise_DMPropertyOrdinalPositionIsSet()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedDefaultDMClass();
            IFormatter formatter = new BinaryFormatter();
            MemoryStream memoryStream = new MemoryStream();
            formatter.Serialize(memoryStream, dmClass);
            memoryStream.Seek(0, SeekOrigin.Begin);
            BusinessObjectManager.Instance.ClearLoadedObjects();
            dmClass = (DMClass) formatter.Deserialize(memoryStream);
            //---------------Execute Test ----------------------
            DMProperty dmProp1 = dmClass.CreateDMProp();
            DMProperty dmProp2 = dmClass.CreateDMProp();
            //---------------Test Result -----------------------
            Assert.AreEqual(1, dmProp1.OrdinalPosition);
            Assert.AreEqual(2, dmProp2.OrdinalPosition);
        }

        [Test]
        public void TestCreateDMProperty_ViaRelationship_OrdinalPosition_NextAvailable()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedDefaultDMClass();
            //---------------Execute Test ----------------------
            DMProperty dmProp1 = dmClass.Properties.CreateBusinessObject();
            DMProperty dmProp2 = dmClass.Properties.CreateBusinessObject();
            //---------------Test Result -----------------------
            Assert.AreEqual(1, dmProp1.OrdinalPosition);
            Assert.AreEqual(2, dmProp2.OrdinalPosition);
        }

        #endregion //Move DMProps

        #region Object Identity

        [Test]
        public void TestCreateObjectIdentity()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = new DMClass();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMObjectIdentity identity = dmClass.CreateObjectIdentity();
            //---------------Test Result -----------------------
            Assert.AreSame(dmClass.ObjectIdentity, identity);
            Assert.AreSame(identity.Class, dmClass);
        }

        [Test]
        public void TestCreateObjectIdentity_OneProperty()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = new DMClass();
            DMProperty dmProperty = CreateDmProperty(dmClass);
            //---------------Assert Precondition----------------
            Assert.AreSame(dmClass, dmProperty.Class);
            //---------------Execute Test ----------------------
            DMObjectIdentity identity = dmClass.CreateObjectIdentity(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreSame(dmClass.ObjectIdentity, identity);
            Assert.AreSame(identity.Class, dmClass);
            Assert.AreSame(dmClass.ObjectIdentity, dmProperty.ObjectIdentity);
            Assert.AreSame(identity, dmProperty.ObjectIdentity);
            Assert.AreEqual(1, identity.Properties.Count);
        }

        [Test]
        public void TestCreateObjectIdentity_OneProperty_GuidProp()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = new DMClass();
            DMPropertyType dmPropertyType = TestUtilsShared.CreateUnsavedValidPropertyTypeInfo();
            dmPropertyType.AssemblyName = "System";
            dmPropertyType.PropertyTypeName = "Guid";
            DMProperty dmProperty = CreateDmProperty(dmClass);
            dmProperty.PropertyType = dmPropertyType;
            //---------------Assert Precondition----------------
            Assert.AreSame(dmClass, dmProperty.Class);
            //---------------Execute Test ----------------------
            DMObjectIdentity identity = dmClass.CreateObjectIdentity(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreSame(dmClass.ObjectIdentity, identity);
            Assert.AreSame(identity.Class, dmClass);
            Assert.AreSame(dmClass.ObjectIdentity, dmProperty.ObjectIdentity);
            Assert.AreSame(identity, dmProperty.ObjectIdentity);
            Assert.AreEqual(1, identity.Properties.Count);
        }

        [Test]
        public void Test_SetObjectIdentity_FromNull_SetsObjectIdentityWithSelectedProperties()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass bo = TestUtilsShared.CreateUnsavedValidDMClass();
            TestUtilsShared.CreateUnsavedValidDMProperty(bo);
            DMProperty propertyInfo2 = TestUtilsShared.CreateUnsavedValidDMProperty(bo);
            TestUtilsShared.CreateUnsavedValidDMProperty(bo);
            List<DMProperty> selectedProperties = new List<DMProperty> {propertyInfo2};
            //-------------Assert Preconditions -------------
            Assert.IsNull(bo.ObjectIdentity);
            //---------------Execute Test ----------------------
            bo.SetObjectIdentity(selectedProperties);
            //---------------Test Result -----------------------
            Assert.IsNotNull(bo.ObjectIdentity);
            DMObjectIdentity dmObjectIdentity = bo.ObjectIdentity;
            Assert.AreEqual(1, dmObjectIdentity.Properties.Count);
            Assert.AreSame(propertyInfo2, dmObjectIdentity.Properties[0]);
            Assert.IsNotNull(propertyInfo2.ObjectIdentity);
            Assert.IsTrue(propertyInfo2.IsPartOfObjectIdentity);
            Assert.IsNotNull(dmObjectIdentity.IsObjectID);
            Assert.IsTrue(dmObjectIdentity.IsObjectID.Value);
        }

        [Test]
        public void Test_SetObjectIdentity_FromNull_SetsObjectIdentityWithTwoSelectedProperties()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass bo = TestUtilsShared.CreateUnsavedValidDMClass();
            TestUtilsShared.CreateUnsavedValidDMProperty(bo);
            DMProperty property1 = TestUtilsShared.CreateUnsavedValidDMProperty(bo);

            DMProperty property2 = TestUtilsShared.CreateUnsavedValidDMProperty(bo);
            List<DMProperty> selectedProperties = new List<DMProperty> {property1, property2};
            //-------------Assert Preconditions -------------
            Assert.IsNull(bo.ObjectIdentity);
            Assert.AreEqual(3, bo.Properties.Count);
            //---------------Execute Test ----------------------
            bo.SetObjectIdentity(selectedProperties);
            //---------------Test Result -----------------------
            DMObjectIdentity dmObjectIdentity = bo.ObjectIdentity;
            Assert.IsNotNull(dmObjectIdentity);
            BusinessObjectCollection<DMProperty> idProperties = dmObjectIdentity.Properties;

            Assert.AreEqual(2, idProperties.Count);

            Assert.IsTrue(idProperties.Contains(property1));
            Assert.IsTrue(idProperties.Contains(property2));
            Assert.IsTrue(property1.IsPartOfObjectIdentity);
            Assert.IsNotNull(dmObjectIdentity.IsObjectID);
        }

        [Test]
        public void Test_SetObjectIdentity_FromNull_SetsObjectIdentityWithTwoSelectedProperties_SaveObject()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass bo = TestUtilsShared.CreateUnsavedValidDMClass();
            TestUtilsShared.CreateUnsavedValidDMProperty(bo);
            DMProperty property1 = TestUtilsShared.CreateUnsavedValidDMProperty(bo);

            DMProperty property2 = TestUtilsShared.CreateUnsavedValidDMProperty(bo);
            List<DMProperty> selectedProperties = new List<DMProperty> {property1, property2};
            //-------------Assert Preconditions -------------
            Assert.IsNull(bo.ObjectIdentity);
            Assert.AreEqual(3, bo.Properties.Count);
            //---------------Execute Test ----------------------
            bo.SetObjectIdentity(selectedProperties);
            bo.Save();
            //---------------Test Result -----------------------
            DMObjectIdentity dmObjectIdentity = bo.ObjectIdentity;
            Assert.IsNotNull(dmObjectIdentity);
            BusinessObjectCollection<DMProperty> idProperties = dmObjectIdentity.Properties;

            Assert.AreEqual(2, idProperties.Count);

            Assert.IsTrue(idProperties.Contains(property1));
            Assert.IsTrue(idProperties.Contains(property2));
            Assert.IsTrue(property1.IsPartOfObjectIdentity);
            Assert.IsNotNull(dmObjectIdentity.IsObjectID);
            Assert.IsFalse(dmObjectIdentity.IsObjectID.Value);
        }

        [Test]
        public void Test_SetObjectIdentity_WithOriginalProps_ObjectIDRemainsUnchanged()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass bo = TestUtilsShared.CreateSavedDMClass();
            TestUtilsShared.CreateSavedDMProperty(bo);
            DMProperty propertyInfo2 = TestUtilsShared.CreateSavedDMProperty(bo);
            TestUtilsShared.CreateSavedDMProperty(bo);
            TestUtilsShared.CreateSavedDMProperty(bo);
            TestUtilsShared.CreateSavedDMProperty(bo);
            List<DMProperty> selectedProperties = new List<DMProperty> {propertyInfo2};
            bo.SetObjectIdentity(selectedProperties);
            //-------------Assert Preconditions -------------
            Assert.IsNotNull(bo.ObjectIdentity);
            DMObjectIdentity dmObjectIdentity = bo.ObjectIdentity;
            Assert.AreEqual(1, dmObjectIdentity.Properties.Count);
            Assert.AreSame(propertyInfo2, dmObjectIdentity.Properties[0]);
            Assert.IsNotNull(propertyInfo2.ObjectIdentity);
            Assert.IsTrue(propertyInfo2.IsPartOfObjectIdentity);
            Assert.IsNotNull(dmObjectIdentity.IsObjectID);

            //---------------Execute Test ----------------------
            bo.SetObjectIdentity(selectedProperties);
            //---------------Test Result -----------------------
            Assert.IsNotNull(bo.ObjectIdentity);
            dmObjectIdentity = bo.ObjectIdentity;
            Assert.AreEqual(1, dmObjectIdentity.Properties.Count);
            Assert.AreSame(propertyInfo2, dmObjectIdentity.Properties[0]);
            Assert.IsNotNull(propertyInfo2.ObjectIdentity);
            Assert.IsTrue(propertyInfo2.IsPartOfObjectIdentity);
            Assert.IsNotNull(dmObjectIdentity.IsObjectID);
        }

        [Test]
        public void Test_SetObjectIdentity_ToNull_UpdatesObjectID()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass bo = TestUtilsShared.CreateSavedDMClass();
            TestUtilsShared.CreateSavedDMProperty(bo);
            DMProperty propertyInfo2 = TestUtilsShared.CreateSavedDMProperty(bo);
            TestUtilsShared.CreateSavedDMProperty(bo);
            TestUtilsShared.CreateSavedDMProperty(bo);
            TestUtilsShared.CreateSavedDMProperty(bo);
            List<DMProperty> selectedProperties = new List<DMProperty> {propertyInfo2};
            bo.SetObjectIdentity(selectedProperties);
            //-------------Assert Preconditions -------------
            Assert.IsNotNull(bo.ObjectIdentity);
            DMObjectIdentity dmObjectIdentity = bo.ObjectIdentity;
            Assert.AreEqual(1, dmObjectIdentity.Properties.Count);
            Assert.AreSame(propertyInfo2, dmObjectIdentity.Properties[0]);
            Assert.IsNotNull(propertyInfo2.ObjectIdentity);
            Assert.IsTrue(propertyInfo2.IsPartOfObjectIdentity);
            //---------------Execute Test ----------------------
            bo.SetObjectIdentity(null);
            //---------------Test Result -----------------------
            Assert.IsNotNull(bo.ObjectIdentity);
            Assert.AreEqual(0, bo.ObjectIdentity.Properties.Count);
            Assert.IsNull(propertyInfo2.ObjectIdentity);
            Assert.IsFalse(propertyInfo2.IsPartOfObjectIdentity);
        }

        [Test]
        public void Test_SetObjectIdentity_ToEmptyCollection_UpdatesObjectID()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass bo = TestUtilsShared.CreateSavedDMClass();
            TestUtilsShared.CreateSavedDMProperty(bo);
            DMProperty propertyInfo2 = TestUtilsShared.CreateSavedDMProperty(bo);
            TestUtilsShared.CreateSavedDMProperty(bo);
            TestUtilsShared.CreateSavedDMProperty(bo);
            TestUtilsShared.CreateSavedDMProperty(bo);
            List<DMProperty> selectedProperties = new List<DMProperty> {propertyInfo2};
            bo.SetObjectIdentity(selectedProperties);
            //-------------Assert Preconditions -------------
            Assert.IsNotNull(bo.ObjectIdentity);
            DMObjectIdentity dmObjectIdentity = bo.ObjectIdentity;
            Assert.AreEqual(1, dmObjectIdentity.Properties.Count);
            Assert.AreSame(propertyInfo2, dmObjectIdentity.Properties[0]);
            Assert.IsNotNull(propertyInfo2.ObjectIdentity);
            Assert.IsTrue(propertyInfo2.IsPartOfObjectIdentity);
            //---------------Execute Test ----------------------
            bo.SetObjectIdentity(new List<DMProperty>());
            //---------------Test Result -----------------------
            Assert.IsNotNull(bo.ObjectIdentity);
            Assert.AreEqual(0, bo.ObjectIdentity.Properties.Count);
            Assert.IsNull(propertyInfo2.ObjectIdentity);
            Assert.IsFalse(propertyInfo2.IsPartOfObjectIdentity);
        }

        [Test]
        public void Test_SetObjectIdentity_OneProperty_AddedPropertyTOSelection_ObjectIDShouldHaveBothProperties()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass bo = TestUtilsShared.CreateSavedDMClass();
            TestUtilsShared.CreateSavedDMProperty(bo);
            DMProperty propertyInfo2 = TestUtilsShared.CreateSavedDMProperty(bo);
            DMProperty addedProperty = TestUtilsShared.CreateSavedDMProperty(bo);
            TestUtilsShared.CreateSavedDMProperty(bo);
            TestUtilsShared.CreateSavedDMProperty(bo);
            List<DMProperty> selectedProperties = new List<DMProperty> {propertyInfo2};
            bo.SetObjectIdentity(selectedProperties);
            //-------------Assert Preconditions -------------
            Assert.IsNotNull(bo.ObjectIdentity);
            DMObjectIdentity dmObjectIdentity = bo.ObjectIdentity;
            Assert.AreEqual(1, dmObjectIdentity.Properties.Count);
            Assert.AreSame(propertyInfo2, dmObjectIdentity.Properties[0]);
            Assert.IsNotNull(propertyInfo2.ObjectIdentity);
            Assert.IsTrue(propertyInfo2.IsPartOfObjectIdentity);
            //---------------Execute Test ----------------------
            selectedProperties.Add(addedProperty);
            bo.SetObjectIdentity(selectedProperties);
            //---------------Test Result -----------------------
            Assert.IsNotNull(bo.ObjectIdentity);
            Assert.AreEqual(2, bo.ObjectIdentity.Properties.Count);
            Assert.IsTrue(bo.ObjectIdentity.Properties.Contains(propertyInfo2));
            Assert.IsTrue(bo.ObjectIdentity.Properties.Contains(addedProperty));
            Assert.IsNotNull(propertyInfo2.ObjectIdentity);
            Assert.IsNotNull(addedProperty.ObjectIdentity);
        }
        [Test]
        public void Test_SetObjectIdentity_WhenOneProperty_WhenSaved_AddedPropertyTOSelection_ObjectIDShouldHaveBothProperties()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            TestUtilsShared.CreateSavedDMProperty(dmClass);
            DMProperty propertyInfo2 = TestUtilsShared.CreateSavedDMProperty(dmClass);
            DMProperty addedProperty = TestUtilsShared.CreateSavedDMProperty(dmClass);
            TestUtilsShared.CreateSavedDMProperty(dmClass);
            TestUtilsShared.CreateSavedDMProperty(dmClass);
            List<DMProperty> selectedProperties = new List<DMProperty> {propertyInfo2};
            dmClass.SetObjectIdentity(selectedProperties);
            dmClass.Save();
            //-------------Assert Preconditions -------------
            Assert.IsNotNull(dmClass.ObjectIdentity);
            DMObjectIdentity dmObjectIdentity = dmClass.ObjectIdentity;
            Assert.AreEqual(1, dmObjectIdentity.Properties.Count);
            Assert.AreSame(propertyInfo2, dmObjectIdentity.Properties[0]);
            Assert.IsNotNull(propertyInfo2.ObjectIdentity);
            Assert.IsTrue(propertyInfo2.IsPartOfObjectIdentity);
            //---------------Execute Test ----------------------
            selectedProperties.Add(addedProperty);
            dmClass.SetObjectIdentity(selectedProperties);
            //---------------Test Result -----------------------
            Assert.IsNotNull(dmClass.ObjectIdentity);
            Assert.AreEqual(2, dmClass.ObjectIdentity.Properties.Count);
            Assert.IsTrue(dmClass.ObjectIdentity.Properties.Contains(propertyInfo2));
            Assert.IsTrue(dmClass.ObjectIdentity.Properties.Contains(addedProperty));
            Assert.IsNotNull(propertyInfo2.ObjectIdentity);
            Assert.IsNotNull(addedProperty.ObjectIdentity);
        }


        #endregion //Object Identity

        #region //Unique Constraint 

        [Test]
        public void Test_CreateUniqueConstraint()
        {
            //--------------- Set up test pack ------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            TestUtilsShared.CreateSavedDMProperty(dmClass);
            DMProperty propertyInfo2 = TestUtilsShared.CreateSavedDMProperty(dmClass);
            DMProperty propertyInfo3 = TestUtilsShared.CreateSavedDMProperty(dmClass);
            TestUtilsShared.CreateSavedDMProperty(dmClass);
            TestUtilsShared.CreateSavedDMProperty(dmClass);
            IList<DMProperty> selectedProperties = new List<DMProperty> {propertyInfo2, propertyInfo3};
            string expectedConstraintName = propertyInfo2.PropertyName + "_" + propertyInfo3.PropertyName;
            //--------------- Test Preconditions ----------------
            //--------------- Execute Test ----------------------
            DMUniqueConstraint uniqueConstraint = dmClass.CreateUnsavedUniqueConstraint(selectedProperties);
            //--------------- Test Result -----------------------
            Assert.IsNotNull(uniqueConstraint);
            Assert.AreSame(dmClass, uniqueConstraint.Class);
            Assert.IsTrue(uniqueConstraint.Status.IsNew);
            BusinessObjectCollection<DMUniqueConstraintProperty> uniqueConstraintProperties =
                uniqueConstraint.UniqueConstraintProperties;
            Assert.AreEqual(2, uniqueConstraintProperties.Count);
            Assert.AreEqual(expectedConstraintName, uniqueConstraint.UniqueConstraintName);
        }

        [Test]
        public void Test_Create_UniqueConstraint_WithDuplicateProperties_DoesNotCreate()
        {
            //--------------- Set up test pack ------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            TestUtilsShared.CreateSavedDMProperty(dmClass);
            DMProperty propertyInfo2 = TestUtilsShared.CreateSavedDMProperty(dmClass);
            DMProperty propertyInfo3 = TestUtilsShared.CreateSavedDMProperty(dmClass);
            TestUtilsShared.CreateSavedDMProperty(dmClass);
            TestUtilsShared.CreateSavedDMProperty(dmClass);
            IList<DMProperty> selectedProperties = new List<DMProperty> {propertyInfo2, propertyInfo3};
            DMUniqueConstraint expectedContraint = dmClass.CreateUnsavedUniqueConstraint(selectedProperties);
            //--------------- Test Preconditions ----------------
            Assert.AreEqual(1, dmClass.UniqueConstraints.Count);
            //--------------- Execute Test ----------------------
            DMUniqueConstraint constraint = dmClass.CreateUnsavedUniqueConstraint(selectedProperties);
            //--------------- Test Result -----------------------
            Assert.AreEqual(1, dmClass.UniqueConstraints.Count);
            Assert.AreSame(expectedContraint, constraint);
        }

        [Test]
        public void Test_Create_UniqueConstraint_WithNonDuplicateProperties_DoesCreate()
        {
            //--------------- Set up test pack ------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            TestUtilsShared.CreateSavedDMProperty(dmClass);
            DMProperty propertyInfo2 = TestUtilsShared.CreateSavedDMProperty(dmClass);
            DMProperty propertyInfo3 = TestUtilsShared.CreateSavedDMProperty(dmClass);
            TestUtilsShared.CreateSavedDMProperty(dmClass);
            TestUtilsShared.CreateSavedDMProperty(dmClass);
            IList<DMProperty> selectedProperties = new List<DMProperty> {propertyInfo3};
            dmClass.CreateUnsavedUniqueConstraint(selectedProperties);
            //--------------- Test Preconditions ----------------
            Assert.AreEqual(1, dmClass.UniqueConstraints.Count);
            //--------------- Execute Test ----------------------
            selectedProperties.Add(propertyInfo2);
            dmClass.CreateUnsavedUniqueConstraint(selectedProperties);
            //--------------- Test Result -----------------------
            Assert.AreEqual(2, dmClass.UniqueConstraints.Count);
        }

        [Test]
        public void Test_Create_UniqueConstraint_WithNon_2_DuplicateProperties_DoesCreate()
        {
            //--------------- Set up test pack ------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            TestUtilsShared.CreateSavedDMProperty(dmClass);
            DMProperty propertyInfo2 = TestUtilsShared.CreateSavedDMProperty(dmClass);
            DMProperty propertyInfo3 = TestUtilsShared.CreateSavedDMProperty(dmClass);
            DMProperty propertyInfo4 = TestUtilsShared.CreateSavedDMProperty(dmClass);
            TestUtilsShared.CreateSavedDMProperty(dmClass);
            TestUtilsShared.CreateSavedDMProperty(dmClass);
            IList<DMProperty> selectedProperties = new List<DMProperty> {propertyInfo3, propertyInfo4};
            dmClass.CreateUnsavedUniqueConstraint(selectedProperties);
            //--------------- Test Preconditions ----------------
            Assert.AreEqual(1, dmClass.UniqueConstraints.Count);
            //--------------- Execute Test ----------------------
            dmClass.CreateUnsavedUniqueConstraint(new List<DMProperty> {propertyInfo3, propertyInfo2});
            //--------------- Test Result -----------------------
            Assert.AreEqual(2, dmClass.UniqueConstraints.Count);
        }

        [Test]
        public void Test_Create_ThenDeleteUniqueConstraint_SaveClass_RemovesCreatedDeletedContraint_NoError_FIXBUG()
        {
            //--------------- Set up test pack ------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            TestUtilsShared.CreateSavedDMProperty(dmClass);
            DMProperty propertyInfo2 = TestUtilsShared.CreateSavedDMProperty(dmClass);
            DMProperty propertyInfo3 = TestUtilsShared.CreateSavedDMProperty(dmClass);
            TestUtilsShared.CreateSavedDMProperty(dmClass);
            TestUtilsShared.CreateSavedDMProperty(dmClass);
            IList<DMProperty> selectedProperties = new List<DMProperty> {propertyInfo2, propertyInfo3};
            DMUniqueConstraint uniqueConstraint = dmClass.CreateUnsavedUniqueConstraint(selectedProperties);
            //--------------- Test Preconditions ----------------
            Assert.IsTrue(uniqueConstraint.Status.IsNew);
            Assert.IsFalse(uniqueConstraint.Status.IsDeleted);
            Assert.AreEqual(1, dmClass.UniqueConstraints.Count);
            //--------------- Execute Test ----------------------
            dmClass.UniqueConstraints.MarkForDelete(uniqueConstraint);
            dmClass.Save();
            //--------------- Test Result -----------------------
            Assert.IsTrue(uniqueConstraint.Status.IsNew);
            Assert.IsTrue(uniqueConstraint.Status.IsDeleted);
            Assert.AreEqual(0, dmClass.UniqueConstraints.Count);
        }

        [Test]
        public void Test_CreateUniqueConstraint_NullCollectionDoesNothing()
        {
            //--------------- Set up test pack ------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            //--------------- Test Preconditions ----------------
            //--------------- Execute Test ----------------------
            DMUniqueConstraint uniqueConstraint = dmClass.CreateUnsavedUniqueConstraint(null);
            //--------------- Test Result -----------------------
            Assert.IsNull(uniqueConstraint);
        }

        [Test]
        public void Test_CreateUniqueConstraint_EmptyCollectionDoesNothing()
        {
            //--------------- Set up test pack ------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            //--------------- Test Preconditions ----------------
            //--------------- Execute Test ----------------------
            DMUniqueConstraint uniqueConstraint = dmClass.CreateUnsavedUniqueConstraint(new List<DMProperty>());
            //--------------- Test Result -----------------------
            Assert.IsNull(uniqueConstraint);
        }

        [Test]
        public void Test_WhenSaveClass_AndSuperClassRelationshipIsMarkForDelete_MustAddToTransaction()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass2 = TestUtilsShared.CreateSavedDMClass();
            TestUtilsShared.CreateSavedDMClass();

            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();

            DMInheritanceRelationship superClassRelationship = new DMInheritanceRelationship();
            dmClass.InheritanceSuperClassRelationship = superClassRelationship;
            dmClass.InheritanceSuperClassRelationship.SuperClass = dmClass2;
            dmClass.InheritanceSuperClassRelationship.InheritanceType = ORMapping.ClassTableInheritance;
            dmClass.InheritanceSuperClassRelationship.Save();
            dmClass.Save();
            dmClass.InheritanceSuperClassRelationship.MarkForDelete();
            //---------------Assert Precondition----------------
            Assert.IsTrue(superClassRelationship.Status.IsDeleted);
            Assert.IsFalse(superClassRelationship.Status.IsNew);
            //---------------Execute Test ----------------------
            dmClass.Save();
            //---------------Test Result -----------------------
            Assert.IsTrue(dmClass.InheritanceSuperClassRelationship.Status.IsNew);
            Assert.IsTrue(dmClass.InheritanceSuperClassRelationship.Status.IsDeleted);
        }

        #endregion //Unique Constraint

        [Test]
        public void Test_DMClassNameDoesNotStartWithNumberRule_ShouldBeOnBusinessObject()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            ReadOnlyCollection<IBusinessObjectRule> rules = BOHelper.GetBusinessObjectRules(dmClass);
            //---------------Test Result -----------------------
            TestUtilsShared.AssertHasRuleOfType<DMClassNameDoesNotStartWithNumberRule>(rules);
        }
        [Test]
        public void Test_DMClassNameNotEqualToAssemblyName_ShouldBeOnBusinessObject()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            ReadOnlyCollection<IBusinessObjectRule> rules = BOHelper.GetBusinessObjectRules(dmClass);
            //---------------Test Result -----------------------
            TestUtilsShared.AssertHasRuleOfType<DMClassNameNotEqualToAssemblyName>(rules);
        }

        [Test]
        public void Test_DMClassDuplicateRelationshipNameRule_ShouldBeOnBusinessObject()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            ReadOnlyCollection<IBusinessObjectRule> rules = BOHelper.GetBusinessObjectRules(dmClass);
            //---------------Test Result -----------------------
            TestUtilsShared.AssertHasRuleOfType<DMClassDuplicateRelationshipNameRule>(rules);
        }

        [Test]
        public void Test_DMClassAllSubClassesDiscriminatorsAreEqual_ShouldBeOnBusinessObject()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            ReadOnlyCollection<IBusinessObjectRule> rules = BOHelper.GetBusinessObjectRules(dmClass);
            //---------------Test Result -----------------------
            TestUtilsShared.AssertHasRuleOfType<DMClassAllSubClassesDiscriminatorsAreEqual>(rules);
        }

        [Test]
        public void Test_DMClassSubClassPropertyNameNotSameAsSuperClassPropertyName_ShouldBeOnBusinessObject()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            ReadOnlyCollection<IBusinessObjectRule> rules = BOHelper.GetBusinessObjectRules(dmClass);
            //---------------Test Result -----------------------
            TestUtilsShared.AssertHasRuleOfType<DMClassSubClassPropertyNameNotSameAsSuperClassPropertyName>(rules);
        }

        [Test]
        public void Test_NeedsRegeneration_True_WhenNew()
        {
            //---------------Set up test pack-------------------

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMClass dmClass = new DMClass();
            //---------------Test Result -----------------------
            Assert.IsTrue(dmClass.NeedsRegeneration);
        }


        [Test]
        public void Test_NeedsRegeneration_True_WhenPropertyAdded()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            dmClass.NeedsRegeneration = false;
            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.NeedsRegeneration);
            //---------------Execute Test ----------------------
            dmClass.Properties.CreateBusinessObject();
            //---------------Test Result -----------------------
            Assert.IsTrue(dmClass.NeedsRegeneration);
        }

        [Test]
        public void Test_NeedsRegeneration_True_WhenPropertyDeleted()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty(dmClass);
            dmClass.Save();
            dmClass.NeedsRegeneration = false;
            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.NeedsRegeneration);
            //---------------Execute Test ----------------------
            dmProperty.MarkForDelete();
            //---------------Test Result -----------------------
            Assert.IsTrue(dmClass.NeedsRegeneration);
        }

        [Test]
        public void Test_NeedsRegeneration_ShouldBeSetToTrue_WhenDMProperty_PropertyNameUpdated()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty(dmClass);
            dmClass.Save();
            dmClass.NeedsRegeneration = false;
            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.NeedsRegeneration);
            //---------------Execute Test ----------------------
            dmProperty.PropertyName = TestUtilsShared.GetRandomString();
            //---------------Test Result -----------------------
            Assert.IsTrue(dmProperty.Status.IsDirty);
            Assert.IsTrue(dmProperty.Props["PropertyName"].IsDirty);
            Assert.IsTrue(dmClass.NeedsRegeneration);
        }

        [Test]
        public void Test_NeedsRegeneration_ShouldBeSetToTrue_WhenDMProperty_PropertyTypeUpdated()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty(dmClass);
            dmClass.Save();
            dmClass.NeedsRegeneration = false;
            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.NeedsRegeneration);
            //---------------Execute Test ----------------------
            dmProperty.PropertyType = dmClass.Solution.GetDMPropertyType("System", "Double");
            //---------------Test Result -----------------------
            Assert.IsTrue(dmProperty.Status.IsDirty);
            Assert.IsTrue(dmClass.NeedsRegeneration);
        }

        [Test]
        public void Test_NeedsRegeneration_ShouldBeSetToTrue_WhenDMProperty_DescriptionUpdated()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty(dmClass);
            dmClass.Save();
            dmClass.NeedsRegeneration = false;
            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.NeedsRegeneration);
            //---------------Execute Test ----------------------
            dmProperty.Description = TestUtilsShared.GetRandomString();
            //---------------Test Result -----------------------
            Assert.IsTrue(dmProperty.Status.IsDirty);
            Assert.IsTrue(dmClass.NeedsRegeneration);
        }

        [Test]
        public void Test_NeedsRegeneration_ShouldBeSetToTrue_WhenDMProperty_CompulsoryUpdated()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty(dmClass);
            dmClass.NeedsRegeneration = false;
            dmClass.Save();
            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.NeedsRegeneration);
            //---------------Execute Test ----------------------
            dmProperty.Compulsory = !dmProperty.Compulsory;
            //---------------Test Result -----------------------
            Assert.IsTrue(dmProperty.Status.IsDirty);
            Assert.IsTrue(dmClass.NeedsRegeneration);
        }

        //[Test]
        //public void Test_NeedsRegeneration_ShouldNotSetToTrue_WhenDMProperty_DisplayNameUpdated()
        //{
        //    //---------------Set up test pack-------------------
        //    DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
        //    DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty(dmClass);
        //    dmClass.Save();
        //    dmClass.NeedsRegeneration = false;
        //    //---------------Assert Precondition----------------
        //    Assert.IsFalse(dmClass.NeedsRegeneration);
        //    //---------------Execute Test ----------------------
        //    dmProperty.DisplayName = TestUtilsShared.GetRandomString();
        //    //---------------Test Result -----------------------
        //    Assert.IsTrue(dmProperty.Status.IsDirty);
        //    Assert.IsFalse(dmClass.NeedsRegeneration);
        //}


        [Test]
        public void Test_NeedsRegeneration_ShouldBeSetToTrue_WhenDMProperty_GenerateCodeSetToTrue()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty(dmClass);
            dmClass.Save();
            dmProperty.GenerateCode = false;
            dmClass.NeedsRegeneration = false;

            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.NeedsRegeneration);
            Assert.IsFalse(dmProperty.GenerateCode);
            //---------------Execute Test ----------------------
            dmProperty.GenerateCode = true;
            //---------------Test Result -----------------------
            Assert.IsTrue(dmProperty.Status.IsDirty);
            Assert.IsFalse(Convert.ToBoolean(dmProperty.Props["GenerateCode"].ValueBeforeLastEdit));
            Assert.IsTrue(dmClass.NeedsRegeneration);
        }

        [Test]
        public void Test_NeedsRegeneration_ShouldSetToTrue_WhenDMProperty_MappedDBColumnNameUpdated()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty(dmClass);
            dmClass.Save();
            dmClass.NeedsRegeneration = false;
            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.NeedsRegeneration);
            //---------------Execute Test ----------------------
            dmProperty.MappedDBColumnName = TestUtilsShared.GetRandomString();
            //---------------Test Result -----------------------
            Assert.IsTrue(dmProperty.Status.IsDirty);
            Assert.IsTrue(dmClass.NeedsRegeneration);
        }

        [Test]
        public void Test_NeedsRegeneration_True_WhenOwnerRelationshipAdded()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            dmClass.NeedsRegeneration = false;
            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.NeedsRegeneration);
            //---------------Execute Test ----------------------
            dmClass.OwnerRelationships.CreateBusinessObject();
            //---------------Test Result -----------------------
            Assert.IsTrue(dmClass.NeedsRegeneration);
        }

        [Test]
        public void Test_NeedsRegeneration_True_WhenOwnerRelationshipDeleted()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            DMRelationship dmRelationship = TestUtilsShared.CreateUnsavedValidRelationshipInfo(dmClass);
            dmClass.Save();
            dmClass.NeedsRegeneration = false;
            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.NeedsRegeneration);
            //---------------Execute Test ----------------------
            dmRelationship.MarkForDelete();
            //---------------Test Result -----------------------
            Assert.IsTrue(dmClass.NeedsRegeneration);
        }

        [Test]
        public void Test_NeedsRegeneration_True_WhenOwnerPropertyUpdated()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            DMRelationship dmRelationship = TestUtilsShared.CreateUnsavedValidRelationshipInfo(dmClass);
            dmClass.Save();
            dmClass.NeedsRegeneration = false;
            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.NeedsRegeneration);
            //---------------Execute Test ----------------------
            dmRelationship.RelationshipName = TestUtilsShared.GetRandomString();
            //---------------Test Result -----------------------
            Assert.IsTrue(dmRelationship.Status.IsDirty);
            Assert.IsTrue(dmClass.NeedsRegeneration);
        }

        [Test]
        public void Test_NeedsRegeneration_True_WhenOwnerRelationshipRelationshipNameUpdated()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            DMRelationship relationship = dmClass.OwnerRelationships.CreateBusinessObject();
            dmClass.NeedsRegeneration = false;
            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.NeedsRegeneration);
            //---------------Execute Test ----------------------
            relationship.RelationshipName = TestUtilsShared.GetRandomString();
            //---------------Test Result -----------------------
            Assert.IsTrue(dmClass.NeedsRegeneration);
        }

        [Test]
        public void Test_NeedsRegeneration_True_WhenOwnerRelationship_CardinalityUpdated()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            DMRelationship relationship = dmClass.OwnerRelationships.CreateBusinessObject();
            dmClass.NeedsRegeneration = false;
            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.NeedsRegeneration);
            //---------------Execute Test ----------------------
            relationship.Cardinality = Cardinality.Multiple;
            //---------------Test Result -----------------------
            Assert.IsTrue(dmClass.NeedsRegeneration);
        }

        [Test]
        public void Test_NeedsRegeneration_True_WhenOwnerRelationship_RelationshipDescriptionUpdated()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            DMRelationship relationship = dmClass.OwnerRelationships.CreateBusinessObject();
            dmClass.NeedsRegeneration = false;
            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.NeedsRegeneration);
            //---------------Execute Test ----------------------
            relationship.RelationshipDescription = TestUtilsShared.GetRandomString();
            //---------------Test Result -----------------------
            Assert.IsTrue(dmClass.NeedsRegeneration);
        }

        [Test]
        public void Test_NeedsRegeneration_ShouldSetToTrue_WhenOwnerRelationship_DeleteActionUpdated()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            DMRelationship relationship = dmClass.OwnerRelationships.CreateBusinessObject();
            dmClass.NeedsRegeneration = false;
            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.NeedsRegeneration);
            //---------------Execute Test ----------------------
            relationship.DeleteAction = DeleteParentAction.DereferenceRelated;
            //---------------Test Result -----------------------
            Assert.IsTrue(dmClass.NeedsRegeneration);
        }

        [Test]
        public void Test_NeedsRegeneration_ShouldSetToTrue_WhenOwnerRelationship_InsertParentActionUpdated()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            DMRelationship relationship = dmClass.OwnerRelationships.CreateBusinessObject();
            dmClass.NeedsRegeneration = false;
            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.NeedsRegeneration);
            //---------------Execute Test ----------------------
            relationship.InsertParentAction = InsertParentAction.InsertRelationship;
            //---------------Test Result -----------------------
            Assert.IsTrue(dmClass.NeedsRegeneration);
        }

        [Test]
        public void Test_NeedsRegeneration_ShouldSetToTrue_WhenOwnerRelationship_RelationshipTypeUpdated()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            DMRelationship relationship = dmClass.OwnerRelationships.CreateBusinessObject();
            dmClass.NeedsRegeneration = false;
            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.NeedsRegeneration);
            //---------------Execute Test ----------------------
            relationship.RelationshipType = RelationshipType.Composition;
            //---------------Test Result -----------------------
            Assert.IsTrue(dmClass.NeedsRegeneration);
        }

        [Test]
        public void Test_NeedsRegeneration_ShouldBeSetToTrue_WhenOwnerRelationship_GenerateCodeSetToTrue()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            DMRelationship relationship = dmClass.OwnerRelationships.CreateBusinessObject();
            relationship.GenerateCode = false;
            dmClass.NeedsRegeneration = false;
            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.NeedsRegeneration);
            //---------------Execute Test ----------------------
            relationship.GenerateCode = true;
            //---------------Test Result -----------------------
            Assert.IsTrue(relationship.Status.IsDirty);
            Assert.IsFalse(Convert.ToBoolean(relationship.Props["GenerateCode"].ValueBeforeLastEdit));
            Assert.IsTrue(dmClass.NeedsRegeneration);
        }

        //[Test]
        //public void Test_NeedsRegeneration_True_WhenOwnerRelationshipRevRelClassChanged()
        //{
        //    //---------------Set up test pack-------------------
        //    DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
        //    DMRelationship relationship = dmClass.OwnerRelationships.CreateBusinessObject();
        //    dmClass.NeedsRegeneration = false;
        //    //---------------Assert Precondition----------------
        //    Assert.IsFalse(dmClass.NeedsRegeneration);
        //    //---------------Execute Test ----------------------
        //    relationship.RelatedClass = TestUtilsShared.CreateUnsavedValidDMClass();
        //    //---------------Test Result -----------------------
        //    Assert.IsTrue(dmClass.NeedsRegeneration);
        //}

        private static DMProperty CreateDmProperty(DMClass dmClass)
        {
            DMProperty dmProperty = TestUtilsDMProperty.CreateUnsavedValidDMProperty(dmClass);
            return dmProperty;
        }
/*
        private static DMProperty CreateDmProperty(DMClass dmClass)
        {
            return CreateDmProperty(dmClass, GetRandomString());
        }*/

        private static DMProperty CreateDmProperty(DMClass dmClass, string propertyName)
        {
            DMProperty dmProperty = new DMProperty();
            dmProperty.PropertyName = propertyName;
            dmClass.Properties.Add(dmProperty);
            return dmProperty;
        }
        [Test]
        public void Test_NonOIDProperties_ReturnsPropsNotPartOfOID()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateSavedDMClassWithOID(3);
            BusinessObjectCollection<DMProperty> oidProps = dmClass.ObjectIdentity.Properties;
            //---------------Assert Precondition----------------
            Assert.AreEqual(4, dmClass.Properties.Count);
            Assert.AreEqual(1, oidProps.Count);
            //---------------Execute Test ----------------------
            List<DMProperty> nonOIDProps = dmClass.NonOIDProperties;
            //---------------Test Result -----------------------
            Assert.AreEqual(3, nonOIDProps.Count);
            Assert.IsFalse(nonOIDProps.Contains(oidProps[0]));
        }

        [Test]
        public void Test_NonOIDProperties_WhenCompositeKey_ReturnsPropsNotPartOfOID()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateSavedDMClassWithCompositeOID(3, 2);
            BusinessObjectCollection<DMProperty> oidProps = dmClass.ObjectIdentity.Properties;
            //---------------Assert Precondition----------------
            Assert.AreEqual(5, dmClass.Properties.Count);
            Assert.AreEqual(3, oidProps.Count);
            //---------------Execute Test ----------------------
            List<DMProperty> nonOIDProps = dmClass.NonOIDProperties;
            //---------------Test Result -----------------------
            Assert.AreEqual(2, nonOIDProps.Count);
            Assert.IsFalse(nonOIDProps.Contains(oidProps[0]));
        }

        [Test]
        public void Test_IsSinglePropID_WhenNoObjectID_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedDefaultDMClass();
            //---------------Assert Precondition----------------
            Assert.IsNull(dmClass.ObjectIdentity);
            //---------------Execute Test ----------------------
            var isSinglePropObjectID = dmClass.IsSinglePropObjectID;
            //---------------Test Result -----------------------
            Assert.IsFalse(isSinglePropObjectID);
        }

        [Test]
        public void Test_IsSinglePropID_WhenNoProps_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedDefaultDMClass();
            dmClass.ObjectIdentity = new DMObjectIdentity();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmClass.ObjectIdentity);
            Assert.AreEqual(0, dmClass.ObjectIdentity.Properties.Count);
            //---------------Execute Test ----------------------
            var isSinglePropObjectID = dmClass.IsSinglePropObjectID;
            //---------------Test Result -----------------------
            Assert.IsFalse(isSinglePropObjectID);
        }

        [Test]
        public void Test_IsSinglePropID_WhenTwoProps_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedDefaultDMClass();
            dmClass.ObjectIdentity = new DMObjectIdentity();
            dmClass.ObjectIdentity.Properties.CreateBusinessObject();
            dmClass.ObjectIdentity.Properties.CreateBusinessObject();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmClass.ObjectIdentity);
            Assert.AreEqual(2, dmClass.ObjectIdentity.Properties.Count);
            //---------------Execute Test ----------------------
            var isSinglePropObjectID = dmClass.IsSinglePropObjectID;
            //---------------Test Result -----------------------
            Assert.IsFalse(isSinglePropObjectID);
        }

        [Test]
        public void Test_IsSinglePropID_WhenOneProps_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedDefaultDMClass();
            dmClass.ObjectIdentity = new DMObjectIdentity();
            dmClass.ObjectIdentity.Properties.CreateBusinessObject();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmClass.ObjectIdentity);
            Assert.AreEqual(1, dmClass.ObjectIdentity.Properties.Count);
            //---------------Execute Test ----------------------
            var isSinglePropObjectID = dmClass.IsSinglePropObjectID;
            //---------------Test Result -----------------------
            Assert.IsTrue(isSinglePropObjectID);
        }

        [Test]
        public void Test_AllUniqueConstraints_WhenNoSuperClass_ShouldReturnOwnConstraints()
        {
            //---------------Set up test pack-------------------
            DMClass superClass = new DMClass();

            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            IDMClass subClass = dmProperty.Class;
            var constraint = subClass.CreateUnsavedUniqueConstraint(new List<DMProperty> {dmProperty});
            DMInheritanceRelationship inheritanceRelationship = new DMInheritanceRelationship {SuperClass = superClass};
            subClass.InheritanceSuperClassRelationship = inheritanceRelationship;
            //---------------Assert Precondition----------------
            Assert.AreEqual(0, superClass.UniqueConstraints.Count);
            Assert.AreEqual(1, subClass.UniqueConstraints.Count);
            //---------------Execute Test ----------------------
            var allUniqueConstraints = subClass.AllUniqueConstraints;
            //---------------Test Result -----------------------
            Assert.AreEqual(1, allUniqueConstraints.Count);
            Assert.IsTrue(allUniqueConstraints.Contains(constraint), "Should Contain '" + constraint.ToString());
        }

        [Test]
        public void Test_AllUniqueConstraints_WhenHasSuperClass_ShouldReturnSuperClassesConstraints()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            DMClass superClass = (DMClass) dmProperty.Class;
            var constraint = superClass.CreateUnsavedUniqueConstraint(new List<DMProperty> {dmProperty});

            DMClass subClass = new DMClass();
            DMInheritanceRelationship inheritanceRelationship = new DMInheritanceRelationship {SuperClass = superClass};
            subClass.InheritanceSuperClassRelationship = inheritanceRelationship;
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, superClass.UniqueConstraints.Count);
            Assert.AreEqual(0, subClass.UniqueConstraints.Count);
            //---------------Execute Test ----------------------
            var allUniqueConstraints = subClass.AllUniqueConstraints;
            //---------------Test Result -----------------------
            Assert.AreEqual(1, allUniqueConstraints.Count);
            Assert.IsTrue(allUniqueConstraints.Contains(constraint), "Should Contain '" + constraint.ToString());
        }

        [Test]
        public void Test_AllUniqueConstraints_WhenBothHaveConstr_ShouldReturnBothConstraints()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            DMClass superClass = (DMClass) dmProperty.Class;
            var superClassConstr = superClass.CreateUnsavedUniqueConstraint(new List<DMProperty> {dmProperty});

            DMProperty dmPropertysubClass = TestUtilsShared.CreateUnsavedValidDMProperty();
            IDMClass subClass = dmPropertysubClass.Class;
            var subClassConstr = subClass.CreateUnsavedUniqueConstraint(new List<DMProperty> {dmPropertysubClass});

            DMInheritanceRelationship inheritanceRelationship = new DMInheritanceRelationship {SuperClass = superClass};
            subClass.InheritanceSuperClassRelationship = inheritanceRelationship;
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, superClass.UniqueConstraints.Count);
            Assert.AreEqual(1, subClass.UniqueConstraints.Count);
            //---------------Execute Test ----------------------
            var allUniqueConstraints = subClass.AllUniqueConstraints;
            //---------------Test Result -----------------------
            Assert.AreEqual(2, allUniqueConstraints.Count);
            Assert.IsTrue(allUniqueConstraints.Contains(superClassConstr),
                          "Should Contain item '" + superClassConstr.ToString());
            Assert.IsTrue(allUniqueConstraints.Contains(subClassConstr),
                          "Should Contain imte '" + superClassConstr.ToString());
        }

        [Test]
        public void Test_AllUniqueConstraints_WhenHasSuperSuperClassConstraing_ShouldReturnSuperSuperClassesConstraints()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            IDMClass superSuperClass = dmProperty.Class;
            var constraint = superSuperClass.CreateUnsavedUniqueConstraint(new List<DMProperty> {dmProperty});

            DMClass superClass = new DMClass();
            DMInheritanceRelationship superSuperRel = new DMInheritanceRelationship
                                                          {SuperClass = (DMClass) superSuperClass};
            superClass.InheritanceSuperClassRelationship = superSuperRel;

            DMClass subClass = new DMClass();
            DMInheritanceRelationship superRel = new DMInheritanceRelationship {SuperClass = superClass};
            subClass.InheritanceSuperClassRelationship = superRel;
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, superSuperClass.UniqueConstraints.Count);
            Assert.AreEqual(0, superClass.UniqueConstraints.Count);
            Assert.AreEqual(0, subClass.UniqueConstraints.Count);
            //---------------Execute Test ----------------------
            var allUniqueConstraints = subClass.AllUniqueConstraints;
            //---------------Test Result -----------------------
            Assert.AreEqual(1, allUniqueConstraints.Count);
            Assert.IsTrue(allUniqueConstraints.Contains(constraint), "Should Contain '" + constraint.ToString());
        }


        [Test]
        public void Test_SuperClass_WhenSuperClassRelationshipNull_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedDefaultDMClass();
            //---------------Assert Precondition----------------
            Assert.IsNull(dmClass.InheritanceSuperClassRelationship);
            //---------------Execute Test ----------------------
            var superClass = dmClass.SuperClass;
            //---------------Test Result -----------------------
            Assert.IsNull(superClass);
        }

        [Test]
        public void Test_SuperClass_WhenSuperClassRelationshipNotNull_ShouldBeSuperClass()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedDefaultDMClass();
            DMClass superClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            DMInheritanceRelationship inheritanceRelationship = new DMInheritanceRelationship();
            inheritanceRelationship.SuperClass = superClass;
            inheritanceRelationship.SubClass = dmClass;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmClass.InheritanceSuperClassRelationship);
            Assert.IsNotNull(dmClass.InheritanceSuperClassRelationship.SuperClass);
            //---------------Execute Test ----------------------
            var suprClass = dmClass.SuperClass;
            //---------------Test Result -----------------------
            Assert.IsNotNull(suprClass);
            Assert.AreSame(superClass, suprClass);
        }

        [Test]
        public void Test_HasSuperClass_WhenSuperClassRelationshipNull_ShouldBeFalse()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedDefaultDMClass();
            //---------------Assert Precondition----------------
            Assert.IsNull(dmClass.InheritanceSuperClassRelationship);
            //---------------Execute Test ----------------------
            bool superClass = dmClass.HasSuperClass;
            //---------------Test Result -----------------------
            Assert.IsFalse(superClass);
        }

        [Test]
        public void Test_HasSuperClass_WhenSuperClassRelationshipNotNull_ShouldBeTrue()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedDefaultDMClass();
            DMClass superClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            DMInheritanceRelationship inheritanceRelationship = new DMInheritanceRelationship();
            inheritanceRelationship.SuperClass = superClass;
            inheritanceRelationship.SubClass = dmClass;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmClass.InheritanceSuperClassRelationship);
            Assert.IsNotNull(dmClass.InheritanceSuperClassRelationship.SuperClass);
            //---------------Execute Test ----------------------
            bool suprClass = dmClass.HasSuperClass;
            //---------------Test Result -----------------------
            Assert.IsTrue(suprClass);
        }

        [Test]
        public void Test_GetObjectID_WhenObjectIDHasNoProps_AndHasSuperClass_ShouldReturnSuperClassObjectID()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedDefaultDMClass();
            DMClass superClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            TestUtilsDMObjectIdentity.CreateSavedDMObjectIdentity(superClass);
            DMInheritanceRelationship inheritanceRelationship = new DMInheritanceRelationship();
            inheritanceRelationship.SuperClass = superClass;
            inheritanceRelationship.SubClass = dmClass;
            dmClass.ObjectIdentity = new DMObjectIdentity();
            //---------------Assert Precondition----------------
            Assert.IsTrue(dmClass.HasSuperClass);
            Assert.AreEqual(0, dmClass.ObjectIdentity.Properties.Count);
            Assert.IsNotNull(superClass.ObjectIdentity);
            Assert.IsTrue(superClass.ObjectIdentity.HasSingleProperties);
            //---------------Execute Test ----------------------
            var objectIdentity = dmClass.GetObjectID();
            //---------------Test Result -----------------------
            Assert.IsNotNull(objectIdentity);
            Assert.AreNotSame(dmClass.ObjectIdentity, objectIdentity);
        }

        [Test]
        public void Test_FullName_WhenAssemblyNull_ShouldReturnClassName()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateSavedDMClass();
            dmClass.Assembly = null;
            //---------------Assert Precondition----------------
            Assert.IsNull(dmClass.Assembly);
            Assert.IsNotNull(dmClass.ClassNameBO);
            //---------------Execute Test ----------------------
            var fullName = dmClass.FullName;
            //---------------Test Result -----------------------
            Assert.AreEqual(dmClass.ClassNameBO, fullName);
        }

        [Test]
        public void Test_FullName_ShouldReturnAssemblyNameClassName()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateSavedDMClass();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmClass.Assembly);
            Assert.IsNotNull(dmClass.ClassNameBO);
            //---------------Execute Test ----------------------
            var fullName = dmClass.FullName;
            //---------------Test Result -----------------------
            Assert.AreEqual(dmClass.Assembly.Name + "." + dmClass.ClassNameBO, fullName);
        }

        [Test]
        public void Test_AssemblyName_ShouldReturnAssemblysName()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            dmClass.Assembly = TestUtilsDMAssembly.CreateUnsavedValidDMAssembly();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmClass.Assembly);
            //---------------Execute Test ----------------------
            var assemblyName = dmClass.AssemblyName;
            //---------------Test Result -----------------------
            Assert.AreEqual(dmClass.Assembly.Name, assemblyName);
        }

        [Test]
        public void Test_AssemblyName_WhenAssemblyNull_ShouldRetEmptyString()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            //---------------Assert Precondition----------------
            Assert.IsNull(dmClass.Assembly);
            //---------------Execute Test ----------------------
            var assemblyName = dmClass.AssemblyName;
            //---------------Test Result -----------------------
            Assert.AreEqual("", assemblyName);
        }


        [Test]
        public void Test_GetDMProperty_WhenSuperClass_ShouldReturnSuperClassesDMProp()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            CreateDmProperty(dmClass);
            CreateDmProperty(dmClass);

            DMClass superClass = new DMClass();
            DMProperty dmProperty3 = CreateDmProperty(superClass);
            CreateDmProperty(superClass);
            dmClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship {SuperClass = superClass};
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var returnedProp = dmClass.GetDMProperty(dmProperty3.PropertyName);
            //---------------Test Result -----------------------
            Assert.AreSame(dmProperty3, returnedProp);
        }

        [Test]
        public void Test_GetDMProperty_WhenOnSubClass_ShouldReturnClassDMProp()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            var dmProperty1 = CreateDmProperty(dmClass);
            CreateDmProperty(dmClass);

            DMClass superClass = new DMClass();
            CreateDmProperty(superClass);
            CreateDmProperty(superClass);
            dmClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship {SuperClass = superClass};
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var returnedProp = dmClass.GetDMProperty(dmProperty1.PropertyName);
            //---------------Test Result -----------------------
            Assert.AreSame(dmProperty1, returnedProp);
        }

        [Test]
        public void Test_GetDMProperty_WhenNotExists_ShouldRetNull()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            CreateDmProperty(dmClass);
            CreateDmProperty(dmClass);

            DMClass superClass = new DMClass();
            CreateDmProperty(superClass);
            CreateDmProperty(superClass);
            dmClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship {SuperClass = superClass};
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var returnedProp = dmClass.GetDMProperty(TestUtilsShared.GetRandomString());
            //---------------Test Result -----------------------
            Assert.IsNull(returnedProp);
        }

        [Test]
        public void Test_HasProperty_WhenNonExists_ShouldRetFalse()
        {
            DMClass dmClass = new DMClass();
            CreateDmProperty(dmClass);
            CreateDmProperty(dmClass);

            DMClass superClass = new DMClass();
            CreateDmProperty(superClass);
            CreateDmProperty(superClass);
            dmClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship { SuperClass = superClass };
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var hasProperty = dmClass.HasProperty(TestUtilsShared.GetRandomString());
            //---------------Test Result -----------------------
            Assert.IsFalse(hasProperty);
        }
        [Test]
        public void Test_HasProperty_WhenExistsOnSubClass_ShouldRetTrue()
        {
            DMClass dmClass = new DMClass();
            var subClassPropertyName = CreateDmProperty(dmClass).PropertyName;
            CreateDmProperty(dmClass);

            DMClass superClass = new DMClass();
            CreateDmProperty(superClass);
            CreateDmProperty(superClass);
            dmClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship { SuperClass = superClass };
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var hasProperty = dmClass.HasProperty(subClassPropertyName);
            //---------------Test Result -----------------------
            Assert.IsTrue(hasProperty);
        }
        [Test]
        public void Test_HasProperty_WhenExistsOnSuperClass_ShouldRetTrue()
        {
            DMClass dmClass = new DMClass();
            CreateDmProperty(dmClass);
            CreateDmProperty(dmClass);

            DMClass superClass = new DMClass();
            CreateDmProperty(superClass);
            var superClassPropName = CreateDmProperty(superClass).PropertyName;
            dmClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship { SuperClass = superClass };
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var hasProperty = dmClass.HasProperty(superClassPropName);
            //---------------Test Result -----------------------
            Assert.IsTrue(hasProperty);
        }

        [Test]
        public void Test_OwnsProperty_WhenNonExists_ShouldRetFalse()
        {
            DMClass dmClass = new DMClass();
            CreateDmProperty(dmClass);
            CreateDmProperty(dmClass);

            DMClass superClass = new DMClass();
            CreateDmProperty(superClass);
            CreateDmProperty(superClass);
            dmClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship { SuperClass = superClass };
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var ownsProperty = dmClass.OwnsProperty(TestUtilsShared.GetRandomString());
            //---------------Test Result -----------------------
            Assert.IsFalse(ownsProperty);
        }
        [Test]
        public void Test_OwnsProperty_WhenExistsOnClass_ShouldRetTrue()
        {
            DMClass dmClass = new DMClass();
            var subClassPropertyName = CreateDmProperty(dmClass).PropertyName;
            CreateDmProperty(dmClass);

            DMClass superClass = new DMClass();
            CreateDmProperty(superClass);
            CreateDmProperty(superClass);
            dmClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship { SuperClass = superClass };
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var ownsProperty = dmClass.OwnsProperty(subClassPropertyName);
            //---------------Test Result -----------------------
            Assert.IsTrue(ownsProperty);
        }
        [Test]
        public void Test_OwnsProperty_WhenExistsOnSuperClass_ShouldRetFalse()
        {
            DMClass dmClass = new DMClass();
            CreateDmProperty(dmClass);
            CreateDmProperty(dmClass);

            DMClass superClass = new DMClass();
            CreateDmProperty(superClass);
            var superClassPropName = CreateDmProperty(superClass).PropertyName;
            dmClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship { SuperClass = superClass };
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var ownsProperty = dmClass.OwnsProperty(superClassPropName);
            //---------------Test Result -----------------------
            Assert.IsFalse(ownsProperty);
        }
        [Test]
        public void Test_GetParent()
        {
            //---------------Set up test pack-------------------
            DMAssembly dmAssembly = new DMAssembly(GetRandomString());
            DMClass dmClass = new DMClass();
            dmAssembly.Classes.Add(dmClass);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IModelElement parent = ((IModelClass)dmClass).Parent;
            //---------------Test Result -----------------------
            Assert.AreSame(dmAssembly, parent);
        }

        [Test]
        public void Test_SetParentExceptionThrown()
        {
            //---------------Set up test pack-------------------
            IModelClass modelClass = new DMClass();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                modelClass.Parent = new DMAssembly();
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            StringAssert.Contains
                ("Set the parent of the class by setting the related Assembly object", exceptionThrown.Message);
        }

        [Test]
        public void Test_GetProperties_EmptyCollection()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IList<IModelProperty> properties = ((IModelClass)dmClass).Properties;
            //---------------Test Result -----------------------
            Assert.IsNotNull(properties);
            Assert.AreEqual(0, properties.Count);
        }

        [Test]
        public void Test_GetProperties_IModelClassPropertiesReturnsCorrectProperties()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            DMProperty dmProperty1 = CreateDmProperty(dmClass);
            DMProperty dmProperty2 = CreateDmProperty(dmClass);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IList<IModelProperty> properties = ((IModelClass)dmClass).Properties;
            //---------------Test Result -----------------------
            Assert.AreEqual(2, properties.Count);
            Assert.IsTrue(properties.Contains(dmProperty1));
            Assert.IsTrue(properties.Contains(dmProperty2));
            //            Assert.AreSame(dmProperty1, properties[0]);
            //            Assert.AreSame(dmProperty2, properties[1]);
        }
        [Test]
        public void Test_AllProperties_NoProperties()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            //---------------Assert Precondition----------------
            Assert.AreEqual(0, dmClass.Properties.Count);
            //---------------Execute Test ----------------------
            IList<IModelProperty> allProperties = ((IModelClass)dmClass).AllProperties;
            //---------------Test Result -----------------------
            Assert.IsNotNull(allProperties);
            Assert.AreEqual(0, allProperties.Count);
        }

        [Test]
        public void Test_AllProperties_NoSuperClass()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            DMProperty dmProperty1 = CreateDmProperty(dmClass);
            DMProperty dmProperty2 = CreateDmProperty(dmClass);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IList<IModelProperty> allProperties = ((IModelClass)dmClass).AllProperties;
            //---------------Test Result -----------------------
            Assert.AreEqual(2, allProperties.Count);
            Assert.AreEqual(dmProperty1.PropertyName, allProperties[0].PropertyName);
            Assert.AreEqual(dmProperty2.PropertyName, allProperties[1].PropertyName);
        }

        [Test]
        public void Test_AllProperties_SuperClass_OneLevel()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            DMProperty dmProperty1 = CreateDmProperty(dmClass);
            DMProperty dmProperty2 = CreateDmProperty(dmClass);

            DMClass superClass = new DMClass();
            DMProperty dmProperty3 = CreateDmProperty(superClass);
            DMProperty dmProperty4 = CreateDmProperty(superClass);
            dmClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship { SuperClass = superClass };
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IList<IModelProperty> allProperties = ((IModelClass)dmClass).AllProperties;
            //---------------Test Result -----------------------
            Assert.AreEqual(4, allProperties.Count);
            Assert.AreNotSame(dmProperty1, allProperties[0]);
            Assert.AreNotSame(dmProperty2, allProperties[1]);
            Assert.AreNotSame(dmProperty3, allProperties[2]);
            Assert.AreNotSame(dmProperty4, allProperties[3]);

            Assert.AreEqual(dmProperty1.PropertyName, allProperties[0].PropertyName);
            Assert.AreEqual(dmProperty2.PropertyName, allProperties[1].PropertyName);
            Assert.AreEqual(dmProperty3.PropertyName, allProperties[2].PropertyName);
            Assert.AreEqual(dmProperty4.PropertyName, allProperties[3].PropertyName);

            Assert.AreEqual(dmClass.ClassNameBO, ((IModelClass)((IModelProperty)dmProperty1).Parent).ClassName);
            Assert.AreEqual(dmClass.ClassNameBO, ((IModelClass)((IModelProperty)dmProperty2).Parent).ClassName);
            Assert.AreEqual(dmClass.ClassNameBO, ((IModelClass)((IModelProperty)dmProperty3).Parent).ClassName);
            Assert.AreEqual(dmClass.ClassNameBO, ((IModelClass)((IModelProperty)dmProperty4).Parent).ClassName);
        }
/*
        [Test]
        public void Test_AllProperties_NoProperties()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            //---------------Assert Precondition----------------
            Assert.AreEqual(0, dmClass.Properties.Count);
            //---------------Execute Test ----------------------
            IList<IModelProperty> allProperties = ((IModelClass)dmClass).AllProperties;
            //---------------Test Result -----------------------
            Assert.IsNotNull(allProperties);
            Assert.AreEqual(0, allProperties.Count);
        }

        [Test]
        public void Test_AllProperties_NoSuperClass()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            DMProperty dmProperty1 = CreateDmProperty(dmClass);
            DMProperty dmProperty2 = CreateDmProperty(dmClass);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IList<IModelProperty> allProperties = ((IModelClass)dmClass).AllProperties;
            //---------------Test Result -----------------------
            Assert.AreEqual(2, allProperties.Count);
            Assert.AreEqual(dmProperty1.PropertyName, allProperties[0].PropertyName);
            Assert.AreEqual(dmProperty2.PropertyName, allProperties[1].PropertyName);
        }*/
/*
        [Test]
        public void Test_AllProperties_SuperClass_OneLevel()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            DMProperty dmProperty1 = CreateDmProperty(dmClass);
            DMProperty dmProperty2 = CreateDmProperty(dmClass);

            DMClass superClass = new DMClass();
            DMProperty dmProperty3 = CreateDmProperty(superClass);
            DMProperty dmProperty4 = CreateDmProperty(superClass);
            dmClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship();
            dmClass.InheritanceSuperClassRelationship.SuperClass = superClass;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IList<IModelProperty> allProperties = ((IModelClass)dmClass).AllProperties;
            //---------------Test Result -----------------------
            Assert.AreEqual(4, allProperties.Count);
            Assert.AreNotSame(dmProperty1, allProperties[0]);
            Assert.AreNotSame(dmProperty2, allProperties[1]);
            Assert.AreNotSame(dmProperty3, allProperties[2]);
            Assert.AreNotSame(dmProperty4, allProperties[3]);

            Assert.AreEqual(dmProperty1.PropertyName, allProperties[0].PropertyName);
            Assert.AreEqual(dmProperty2.PropertyName, allProperties[1].PropertyName);
            Assert.AreEqual(dmProperty3.PropertyName, allProperties[2].PropertyName);
            Assert.AreEqual(dmProperty4.PropertyName, allProperties[3].PropertyName);

            Assert.AreEqual(dmClass.ClassNameBO, ((IModelClass)((IModelProperty)dmProperty1).Parent).ClassName);
            Assert.AreEqual(dmClass.ClassNameBO, ((IModelClass)((IModelProperty)dmProperty2).Parent).ClassName);
            Assert.AreEqual(dmClass.ClassNameBO, ((IModelClass)((IModelProperty)dmProperty3).Parent).ClassName);
            Assert.AreEqual(dmClass.ClassNameBO, ((IModelClass)((IModelProperty)dmProperty4).Parent).ClassName);
        }*/

    /*    [Test]
        public void Test_AllProperties_SuperClass_TwoLevel()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            DMProperty dmProperty1 = CreateDmProperty(dmClass);

            DMClass superClass = new DMClass();
            DMProperty dmProperty2 = CreateDmProperty(superClass);

            DMClass grandClass = new DMClass();
            DMProperty dmProperty3 = CreateDmProperty(grandClass);
            superClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship();
            superClass.InheritanceSuperClassRelationship.SuperClass = grandClass;

            dmClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship();
            dmClass.InheritanceSuperClassRelationship.SuperClass = superClass;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IList<IModelProperty> allProperties = ((IModelClass)dmClass).AllProperties;
            //---------------Test Result -----------------------
            Assert.AreEqual(3, allProperties.Count);
            Assert.AreNotSame(dmProperty1, allProperties[0]);
            Assert.AreNotSame(dmProperty2, allProperties[1]);
            Assert.AreNotSame(dmProperty3, allProperties[2]);

            Assert.AreEqual(dmProperty1.PropertyName, allProperties[0].PropertyName);
            Assert.AreEqual(dmProperty2.PropertyName, allProperties[1].PropertyName);
            Assert.AreEqual(dmProperty3.PropertyName, allProperties[2].PropertyName);

            Assert.AreEqual(dmClass.ClassNameBO, ((IModelClass)((IModelProperty)dmProperty1).Parent).ClassName);
            Assert.AreEqual(dmClass.ClassNameBO, ((IModelClass)((IModelProperty)dmProperty2).Parent).ClassName);
            Assert.AreEqual(dmClass.ClassNameBO, ((IModelClass)((IModelProperty)dmProperty3).Parent).ClassName);
        }*/


        [Test]
        public void Test_Relationships_EmptyCollection()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IList<IModelRelationship> relationships = ((IModelClass)dmClass).Relationships;
            //---------------Test Result -----------------------
            Assert.IsNotNull(relationships);
            Assert.AreEqual(0, relationships.Count);
        }

        [Test]
        public void Test_Relationships()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            DMRelationship dmRelationship1 = CreateDmRelationship(dmClass);
            DMRelationship dmRelationship2 = CreateDmRelationship(dmClass);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IList<IModelRelationship> relationships = ((IModelClass)dmClass).Relationships;
            //---------------Test Result -----------------------
            Assert.AreEqual(2, relationships.Count);
            Assert.AreSame(dmRelationship1, relationships[0]);
            Assert.AreSame(dmRelationship2, relationships[1]);
        }

        [Test]
        public void Test_AllRelationships_NoRelationships()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            //---------------Assert Precondition----------------
            Assert.AreEqual(0, dmClass.OwnerRelationships.Count);
            //---------------Execute Test ----------------------
            IList<IModelRelationship> allRelationships = ((IModelClass)dmClass).AllRelationships;
            //---------------Test Result -----------------------
            Assert.IsNotNull(allRelationships);
            Assert.AreEqual(0, allRelationships.Count);
        }

        [Test]
        public void Test_AllRelationships_NoSuperClass()
        {
            //---------------Set up test pack-------------------
            DMSolution solution = TestUtilsDMSolution.CreateUnsavedValidDMSolution();
            DMRelationship dmRelationship1;
            DMRelationship dmRelationship2;
            DMClass dmClass = CreateDMClassWithTwoRelationships(solution, out dmRelationship1, out dmRelationship2);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IList<IModelRelationship> allRelationships = ((IModelClass)dmClass).AllRelationships;
            //---------------Test Result -----------------------
            Assert.AreEqual(2, allRelationships.Count);
            AssertRelationshipsAreEqual(dmRelationship1, allRelationships[0]);
            AssertRelationshipsAreEqual(dmRelationship2, allRelationships[1]);
        }

        private static void AssertRelationshipsAreEqual(DMRelationship expectedRelationship, IModelRelationship actualRelationship)
        {
            Assert.AreEqual(expectedRelationship.RelationshipName, actualRelationship.RelationshipName);
            Assert.AreEqual(expectedRelationship.RelationshipProperties[0].OwnerPropertyName, actualRelationship.PropertyName);
            Assert.AreEqual(expectedRelationship.RelationshipProperties[0].RelatedPropertyName, actualRelationship.RelatedPropertyName);
        }

        private static DMClass CreateDMClassWithTwoRelationships(DMSolution solution, out DMRelationship dmRelationship1, out DMRelationship dmRelationship2)
        {
            DMClass childClass;
            DMClass parentClass = CreateDMClassWithOneRelationship(solution, out dmRelationship1, out childClass);
            dmRelationship2 = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(childClass, parentClass);
            dmRelationship2 = (DMRelationship)dmRelationship2.ReverseRelationship;
            return parentClass;
        }

        private static DMClass CreateDMClassWithOneRelationship(DMSolution solution, out DMRelationship dmRelationship1)
        {
            DMClass childClass;
            return CreateDMClassWithOneRelationship(solution, out dmRelationship1, out childClass);
        }

        private static DMClass CreateDMClassWithOneRelationship(DMSolution solution, out DMRelationship dmRelationship1, out DMClass childClass)
        {
            DMClass parentClass = TestUtilsDMClass.CreateDMClassWithObjectIdentity(solution, "ParentClass");
            childClass = TestUtilsDMClass.CreateDMClassWithObjectIdentity(solution, "ChildClass");
            dmRelationship1 = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            return parentClass;
        }

        [Test]
        public void Test_AllRelationships_SuperClass_OneLevel()
        {
            //---------------Set up test pack-------------------
            DMSolution solution = TestUtilsDMSolution.CreateUnsavedValidDMSolution();
            DMRelationship dmRelationship1;
            DMRelationship dmRelationship2;
            DMClass dmClass = CreateDMClassWithTwoRelationships(solution, out dmRelationship1, out dmRelationship2);

            DMRelationship dmRelationship3;
            DMRelationship dmRelationship4;
            DMClass superClass = CreateDMClassWithTwoRelationships(solution, out dmRelationship3, out dmRelationship4);

            dmClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship();
            dmClass.InheritanceSuperClassRelationship.SuperClass = superClass;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IList<IModelRelationship> allRelationships = ((IModelClass)dmClass).AllRelationships;
            //---------------Test Result -----------------------
            Assert.AreEqual(4, allRelationships.Count);
            AssertRelationshipsAreEqual(dmRelationship1, allRelationships[0]);
            AssertRelationshipsAreEqual(dmRelationship2, allRelationships[1]);
            AssertRelationshipsAreEqual(dmRelationship3, allRelationships[2]);
            AssertRelationshipsAreEqual(dmRelationship4, allRelationships[3]);

            Assert.AreEqual
                (dmClass.ClassNameBO, ((IModelClass)((IModelRelationship)dmRelationship1).Parent).ClassName);
            Assert.AreEqual
                (dmClass.ClassNameBO, ((IModelClass)((IModelRelationship)dmRelationship2).Parent).ClassName);
            Assert.AreEqual
                (dmClass.ClassNameBO, ((IModelClass)((IModelRelationship)dmRelationship3).Parent).ClassName);
            Assert.AreEqual
                (dmClass.ClassNameBO, ((IModelClass)((IModelRelationship)dmRelationship4).Parent).ClassName);
        }
        [Test]
        public void Test_AllRelationships_SuperClass_OneLevel_ShouldReturnSameInstances()
        {
            //This is testing that once the object is cloned it is not recloned for every call.
            //---------------Set up test pack-------------------
            DMSolution solution = TestUtilsDMSolution.CreateUnsavedValidDMSolution();
            DMRelationship dmRelationship1;
            DMRelationship dmRelationship2;
            DMClass dmClass = CreateDMClassWithTwoRelationships(solution, out dmRelationship1, out dmRelationship2);

            DMRelationship dmRelationship3;
            DMRelationship dmRelationship4;
            DMClass superClass = CreateDMClassWithTwoRelationships(solution, out dmRelationship3, out dmRelationship4);

            dmClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship();
            dmClass.InheritanceSuperClassRelationship.SuperClass = superClass;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IList<IModelRelationship> allRelationships = ((IModelClass)dmClass).AllRelationships;
            IList<IModelRelationship> allRelationshipsSecondCall = ((IModelClass)dmClass).AllRelationships;
            //---------------Test Result -----------------------
            Assert.AreEqual(allRelationships, allRelationshipsSecondCall);
            Assert.AreSame(allRelationships.First(), allRelationshipsSecondCall.First());
            Assert.AreSame(allRelationships.Last(), allRelationshipsSecondCall.Last());
        }
        
        [Test]
        public void Test_AllRelationships_SuperClass_TwoLevel()
        {
            //---------------Set up test pack-------------------
            DMSolution solution = TestUtilsDMSolution.CreateUnsavedValidDMSolution();
            DMRelationship dmRelationship1;
            DMClass dmClass = CreateDMClassWithOneRelationship(solution, out dmRelationship1);

            DMRelationship dmRelationship2;
            DMClass superClass = CreateDMClassWithOneRelationship(solution, out dmRelationship2);

            DMRelationship dmRelationship3;
            DMClass grandClass = CreateDMClassWithOneRelationship(solution, out dmRelationship3);

            superClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship();
            superClass.InheritanceSuperClassRelationship.SuperClass = grandClass;

            dmClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship();
            dmClass.InheritanceSuperClassRelationship.SuperClass = superClass;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IList<IModelRelationship> allRelationships = ((IModelClass)dmClass).AllRelationships;
            //---------------Test Result -----------------------
            Assert.AreEqual(3, allRelationships.Count);
            Assert.AreNotSame(dmRelationship1, allRelationships[0]);
            Assert.AreNotSame(dmRelationship2, allRelationships[1]);
            Assert.AreNotSame(dmRelationship3, allRelationships[2]);

            AssertRelationshipsAreEqual(dmRelationship1, allRelationships[0]);
            AssertRelationshipsAreEqual(dmRelationship2, allRelationships[1]);
            AssertRelationshipsAreEqual(dmRelationship3, allRelationships[2]);

            Assert.AreEqual
                (dmClass.ClassNameBO, ((IModelClass)((IModelRelationship)dmRelationship1).Parent).ClassName);
            Assert.AreEqual
                (dmClass.ClassNameBO, ((IModelClass)((IModelRelationship)dmRelationship2).Parent).ClassName);
            Assert.AreEqual
                (dmClass.ClassNameBO, ((IModelClass)((IModelRelationship)dmRelationship3).Parent).ClassName);
        }

        [Test]
        public void Test_AssemblyName()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            string assemblyName = GetRandomString();
            DMAssembly dmAssembly = new DMAssembly(assemblyName);
            dmAssembly.Classes.Add(modelClass);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string newAssemblyName = ((IModelClass)modelClass).AssemblyName;
            //---------------Test Result -----------------------
            Assert.AreEqual(assemblyName, newAssemblyName);
        }

        private static string GetRandomString()
        {
            return TestUtilsShared.GetRandomString();
        }

        [Test]
        public void Test_AssemblyName_NoAssembly()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string newAssemblyName = ((IModelClass)modelClass).AssemblyName;
            //---------------Test Result -----------------------
            Assert.AreEqual("", newAssemblyName);
        }

        [Test]
        public void Test_SuperClassName()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            DMClass superClass = new DMClass();
            string superClassName = GetRandomString();
            superClass.ClassNameBO = superClassName;
            dmInheritanceRelationship.SuperClass = superClass;
            modelClass.InheritanceSuperClassRelationship = dmInheritanceRelationship;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string superClassName1 = ((IModelClass)modelClass).SuperClassName;
            //---------------Test Result -----------------------
            Assert.AreEqual(superClassName, superClassName1);
        }

        [Test]
        public void Test_SuperClassName_NoSuperClass()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string newSuperClassName = ((IModelClass)modelClass).SuperClassName;
            //---------------Test Result -----------------------
            Assert.AreEqual("", newSuperClassName);
        }
#pragma warning disable 168

        [Test]
        public void Test_SuperClassName_SuperClass_NoClassAssigned_ThrowsException()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            modelClass.InheritanceSuperClassRelationship = dmInheritanceRelationship;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                string newSuperClassName = ((IModelClass)modelClass).SuperClassName;
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            Assert.AreEqual
                (string.Format("DMInheritanceRelationship for '{0}' has not had its SuperClassClass set", modelClass.ClassNameBO),
                 exceptionThrown.Message);
        }


        [Test]
        public void Test_SuperClassAssemblyName()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            DMClass superClass = new DMClass();
            string superClassName = GetRandomString();
            superClass.ClassNameBO = superClassName;
            string superClassAssemblyName = GetRandomString();
            superClass.Assembly = new DMAssembly(superClassAssemblyName);
            dmInheritanceRelationship.SuperClass = superClass;
            modelClass.InheritanceSuperClassRelationship = dmInheritanceRelationship;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string testAssemblyname = ((IModelClass)modelClass).SuperClassAssemblyName;
            //---------------Test Result -----------------------
            Assert.AreEqual(superClassAssemblyName, testAssemblyname);
        }

        [Test]
        public void Test_SuperClassAssemblyName_NoSuperClass()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string testAssemblyname = ((IModelClass)modelClass).SuperClassAssemblyName;
            //---------------Test Result -----------------------
            Assert.AreEqual("", testAssemblyname);
        }

        [Test]
        public void Test_SuperClassAssemblyName_ClassOfSuperClassNotSet_ThrowsException()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            modelClass.ClassNameBO = GetRandomString();
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            modelClass.InheritanceSuperClassRelationship = dmInheritanceRelationship;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                string testAssemblyname = ((IModelClass)modelClass).SuperClassAssemblyName;
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            Assert.AreEqual
                (string.Format("DMInheritanceRelationship for '{0}' has not had its SuperClassClass set", modelClass.ClassNameBO),
                 exceptionThrown.Message);
        }

        [Test]
        public void Test_SuperClassAssemblyName_NoSuperClassAssembly_ThrowsException()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            DMClass superClass = new DMClass();
            string superClassName = GetRandomString();
            superClass.ClassNameBO = superClassName;
            dmInheritanceRelationship.SuperClass = superClass;
            modelClass.InheritanceSuperClassRelationship = dmInheritanceRelationship;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                string testAssemblyname = ((IModelClass)modelClass).SuperClassAssemblyName;
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            Assert.AreEqual
                (string.Format("DMInheritanceRelationship for '{0}' has no Assembly", modelClass.ClassNameBO),
                 exceptionThrown.Message);
        }

        [Test]
        public void Test_SuperClassChildID()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            string childIdentity = GetRandomString();
            dmInheritanceRelationship.Identity = childIdentity;
            modelClass.InheritanceSuperClassRelationship = dmInheritanceRelationship;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string testChildIdentity = ((IModelClass)modelClass).SuperClassChildID;
            //---------------Test Result -----------------------
            Assert.AreEqual(childIdentity, testChildIdentity);
        }

        [Test]
        public void Test_SuperClassChildID_NoSuperClass()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string testChildIdentity = ((IModelClass)modelClass).SuperClassChildID;
            //---------------Test Result -----------------------
            Assert.AreEqual("", testChildIdentity);
        }

        [Test]
        public void Test_SuperClassDiscriminator()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            string discriminator = GetRandomString();
            dmInheritanceRelationship.Discriminator = discriminator;
            modelClass.InheritanceSuperClassRelationship = dmInheritanceRelationship;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string testDiscriminator = ((IModelClass)modelClass).SuperClassDiscriminator;
            //---------------Test Result -----------------------
            Assert.AreEqual(discriminator, testDiscriminator);
        }

        [Test]
        public void Test_SuperClassDiscriminator_NoSuperClass()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string testDiscriminator = ((IModelClass)modelClass).SuperClassDiscriminator;
            //---------------Test Result -----------------------
            Assert.AreEqual("", testDiscriminator);
        }

        [Test]
        public void Test_InheritanceType()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            dmInheritanceRelationship.InheritanceType = ORMapping.ConcreteTableInheritance;
            modelClass.InheritanceSuperClassRelationship = dmInheritanceRelationship;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string inheritanceType = ((IModelClass)modelClass).InheritanceType;
            //---------------Test Result -----------------------
            Assert.AreEqual(ORMapping.ConcreteTableInheritance.ToString(), inheritanceType);
        }

        [Test]
        public void Test_InheritanceType_ThrowsExceptionIfNull()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            dmInheritanceRelationship.InheritanceType = null;
            modelClass.InheritanceSuperClassRelationship = dmInheritanceRelationship;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                string inheritanceType = ((IModelClass)modelClass).InheritanceType;
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            Assert.AreEqual
                (string.Format("Inheritance type for DMInheritanceRelationship of '{0}' cannot be null", modelClass.ClassNameBO),
                 exceptionThrown.Message);
        }

        [Test]
        public void Test_InheritanceType_NoSuperClass()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string inheritanceType = ((IModelClass)modelClass).InheritanceType;
            //---------------Test Result -----------------------
            Assert.AreEqual("", inheritanceType);
        }


        [Test]
        public void Test_TableName()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            string tableName = GetRandomString();
            modelClass.MappedTableName = tableName;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string testTableName = ((IModelClass)modelClass).TableName;
            //---------------Test Result -----------------------
            Assert.AreEqual(tableName, testTableName);
        }


        [Test]
        public void Test_PrimaryKeyProperties()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            DMProperty pkProperty = CreateDmProperty(modelClass, GetRandomString());
            DMObjectIdentity objectIdentity = new DMObjectIdentity();
            objectIdentity.Properties.Add(pkProperty);
            objectIdentity.Class = modelClass;
            DMProperty dmProperty = CreateDmProperty(modelClass);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IList<IModelProperty> primaryKeyProperties = ((IModelClass)modelClass).PrimaryKeyProperties;
            //---------------Test Result -----------------------
            Assert.AreEqual(1, primaryKeyProperties.Count);
            Assert.AreSame(pkProperty, primaryKeyProperties[0]);
        }

        [Test]
        public void Test_PrimaryKeyProperties_ThrowsExceptionIfObjectIdentityNull()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                IList<IModelProperty> primaryKeyProperties = ((IModelClass)modelClass).PrimaryKeyProperties;
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            Assert.AreEqual
                (string.Format("ObjectIdentity for class '{0}' has nor been set.", modelClass.ClassNameBO),
                 exceptionThrown.Message);
        }


        [Test]
        public void Test_PrimaryKeyIsID()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            DMProperty pkProperty = CreateDmProperty(modelClass, GetRandomString());
            DMObjectIdentity objectIdentity = new DMObjectIdentity();
            objectIdentity.Properties.Add(pkProperty);
            objectIdentity.IsObjectID = false;
            objectIdentity.Class = modelClass;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool primaryKeyIsID = ((IModelClass)modelClass).PrimaryKeyIsID;
            //---------------Test Result -----------------------
            Assert.IsFalse(primaryKeyIsID);
        }

        [Test]
        public void Test_PrimaryKeyIsID_ThrowsException_IfObjectIdentityNull()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                bool primaryKeyIsID = ((IModelClass)modelClass).PrimaryKeyIsID;
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            Assert.AreEqual
                (string.Format
                     ("Cannot call PrimaryKeyIsID when ObjectIdentity has not been set, in class: {0}",
                      modelClass.ClassNameBO), exceptionThrown.Message);
        }

        [Test]
        public void Test_HasPrimaryKeyWithProps_WhenHasPKWithProps_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            UpdateClassWithValidObjectID(modelClass);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool hasPrimaryKeyWithProps = ((IModelClass)modelClass).HasPrimaryKeyWithProps;
            //---------------Test Result -----------------------
            Assert.IsTrue(hasPrimaryKeyWithProps);
        }

        private static void UpdateClassWithValidObjectID(DMClass modelClass)
        {
            DMProperty pkProperty = CreateDmProperty(modelClass, GetRandomString());
            DMObjectIdentity objectIdentity = new DMObjectIdentity();
            objectIdentity.Properties.Add(pkProperty);
            objectIdentity.IsObjectID = false;
            objectIdentity.Class = modelClass;
        }

        [Test]
        public void Test_HasPrimaryKeyWithProps_WhenHasPKWithNoProps_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass { ObjectIdentity = new DMObjectIdentity() };
            CreateDmProperty(modelClass, GetRandomString());
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool hasPrimaryKeyWithProps = ((IModelClass)modelClass).HasPrimaryKeyWithProps;
            //---------------Test Result -----------------------
            Assert.IsFalse(hasPrimaryKeyWithProps);
        }
        [Test]
        public void Test_HasPrimaryKeyWithProps_WhenNotHas_AndSuperClassHas_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass superClass = new DMClass();
            UpdateClassWithValidObjectID(superClass);


            DMClass modelClass = new DMClass();
            modelClass.SuperClass = superClass;

            //---------------Assert Precondition----------------
            Assert.IsNull(modelClass.ObjectIdentity);
            Assert.IsNotNull(modelClass.SuperClass);
            Assert.IsNotNull(modelClass.SuperClass.ObjectIdentity);
            Assert.IsNotNull(modelClass.GetObjectID());
            //---------------Execute Test ----------------------
            bool hasPrimaryKeyWithProps = ((IModelClass)modelClass).HasPrimaryKeyWithProps;
            //---------------Test Result -----------------------
            Assert.IsFalse(hasPrimaryKeyWithProps);
        }

        [Test]
        public void Test_HasPrimaryKeyWithProps_WhenHasNoPK_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            CreateDmProperty(modelClass, GetRandomString());
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            bool hasPrimaryKeyWithProps = ((IModelClass)modelClass).HasPrimaryKeyWithProps;
            //---------------Test Result -----------------------
            Assert.IsFalse(hasPrimaryKeyWithProps);
        }

        [Test]
        public void Test_AlternateKeys()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            DMProperty dmProperty1 = CreateDmProperty(modelClass, GetRandomString());
            DMProperty dmProperty2 = CreateDmProperty(modelClass, GetRandomString());
            DMUniqueConstraint uniqueConstraint = new DMUniqueConstraint();
            uniqueConstraint.AddPropertyInfo(dmProperty1);
            uniqueConstraint.Class = modelClass;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IList<IModelKey> alternateKeys = ((IModelClass)modelClass).AlternateKeys;
            //---------------Test Result -----------------------
            Assert.AreEqual(1, alternateKeys.Count);
            Assert.AreSame(uniqueConstraint, alternateKeys[0]);
            Assert.AreEqual(1, alternateKeys[0].KeyProperties.Count);
            Assert.AreSame(dmProperty1, alternateKeys[0].KeyProperties[0]);
        }

        [Test]
        public void Test_HasSuperClass_True()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            modelClass.InheritanceSuperClassRelationship = dmInheritanceRelationship;
            DMClass superClass = new DMClass();
            dmInheritanceRelationship.SuperClass = superClass;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool hasSuperClass = ((IModelClass)modelClass).HasSuperClass;
            //---------------Test Result -----------------------
            Assert.IsTrue(hasSuperClass);
        }

        [Test]
        public void Test_HasSuperClass_False()
        {
            //---------------Set up test pack-------------------
            IModelClass modelClass = new DMClass();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool hasSuperClass = modelClass.HasSuperClass;
            //---------------Test Result -----------------------
            Assert.IsFalse(hasSuperClass);
        }

        [Test, Ignore("TODO 2009/02/23 Eric - Habanero converts empty string to null, fix Habanero")]
        public void Test_SuperClassDefIDIsEmpty_True()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            dmInheritanceRelationship.Identity = "";
            modelClass.InheritanceSuperClassRelationship = dmInheritanceRelationship;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool isEmpty = ((IModelClass)modelClass).SuperClassDefIDIsEmpty;
            //---------------Test Result -----------------------
            Assert.IsTrue(isEmpty);
        }

        [Test]
        public void Test_SuperClassDefIDIsEmpty_False()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            dmInheritanceRelationship.Identity = GetRandomString();
            modelClass.InheritanceSuperClassRelationship = dmInheritanceRelationship;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool isEmpty = ((IModelClass)modelClass).SuperClassDefIDIsEmpty;
            //---------------Test Result -----------------------
            Assert.IsFalse(isEmpty);
        }

        [Test]
        public void Test_SuperClassDefIDIsEmpty_FalseForNull()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            dmInheritanceRelationship.Identity = null;
            modelClass.InheritanceSuperClassRelationship = dmInheritanceRelationship;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool isEmpty = ((IModelClass)modelClass).SuperClassDefIDIsEmpty;
            //---------------Test Result -----------------------
            Assert.IsFalse(isEmpty);
        }

        [Test]
        public void Test_SuperClassDefIDIsEmpty_SuperClassNull_ThrowsException()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                bool isEmpty = ((IModelClass)modelClass).SuperClassDefIDIsEmpty;
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            Assert.AreEqual
                (string.Format
                     ("SuperClassDefIDIsEmpty is being called on class '{0}' when the class has no SuperClass. "
                      + "First check for a SuperClass using HasSuperClass.", modelClass.ClassNameBO),
                 exceptionThrown.Message);
        }

        [Test]
        public void Test_SuperClassDefIDIsNotNullOrEmpty_True()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            dmInheritanceRelationship.Identity = GetRandomString();
            modelClass.InheritanceSuperClassRelationship = dmInheritanceRelationship;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool isNotNullOrEmpty = ((IModelClass)modelClass).SuperClassDefIDIsNotNullOrEmpty;
            //---------------Test Result -----------------------
            Assert.IsTrue(isNotNullOrEmpty);
        }

        [Test]
        public void Test_SuperClassDefIDIsNotNullOrEmpty_FalseForNull()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            dmInheritanceRelationship.Identity = null;
            modelClass.InheritanceSuperClassRelationship = dmInheritanceRelationship;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool isNotNullOrEmpty = ((IModelClass)modelClass).SuperClassDefIDIsNotNullOrEmpty;
            //---------------Test Result -----------------------
            Assert.IsFalse(isNotNullOrEmpty);
        }

        [Test]
        public void Test_SuperClassDefIDIsNotNullOrEmpty_FalseForEmpty()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            dmInheritanceRelationship.Identity = "";
            modelClass.InheritanceSuperClassRelationship = dmInheritanceRelationship;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool isNotNullOrEmpty = ((IModelClass)modelClass).SuperClassDefIDIsNotNullOrEmpty;
            //---------------Test Result -----------------------
            Assert.IsFalse(isNotNullOrEmpty);
        }

        [Test]
        public void Test_SuperClassDefIDIsNotNullOrEmpty_SuperClassNull_ThrowsException()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                bool isNotNullOrEmpty = ((IModelClass)modelClass).SuperClassDefIDIsNotNullOrEmpty;
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            Assert.AreEqual
                (string.Format
                     ("SuperClassDefIDIsNotNullOrEmpty is being called on class '{0}' when the class has no SuperClass. "
                      + "First check for a SuperClass using HasSuperClass.", modelClass.ClassNameBO),
                 exceptionThrown.Message);
        }

        [Test]
        public void Test_SuperClassDefIDIsNull_True()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            dmInheritanceRelationship.Identity = null;
            modelClass.InheritanceSuperClassRelationship = dmInheritanceRelationship;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool isNull = ((IModelClass)modelClass).SuperClassDefIDIsNull;
            //---------------Test Result -----------------------
            Assert.IsTrue(isNull);
        }

        [Test, Ignore("TODO 2009/02/23 Eric - Habanero converts empty string to null, fix Habanero")]
        public void Test_SuperClassDefIDIsNull_FalseForEmpty()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            dmInheritanceRelationship.Identity = "";
            modelClass.InheritanceSuperClassRelationship = dmInheritanceRelationship;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool isNull = ((IModelClass)modelClass).SuperClassDefIDIsNull;
            //---------------Test Result -----------------------
            Assert.IsFalse(isNull);
        }

        [Test]
        public void Test_SuperClassDefIDIsNull_FalseForNonEmpty()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            dmInheritanceRelationship.Identity = GetRandomString();
            modelClass.InheritanceSuperClassRelationship = dmInheritanceRelationship;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool isNull = ((IModelClass)modelClass).SuperClassDefIDIsNull;
            //---------------Test Result -----------------------
            Assert.IsFalse(isNull);
        }

        [Test]
        public void Test_SuperClassDefIDIsNull_SuperClassNull_ThrowsException()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                bool isNull = ((IModelClass)modelClass).SuperClassDefIDIsNull;
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            Assert.AreEqual
                (string.Format
                     ("SuperClassDefIDIsNull is being called on class '{0}' when the class has no SuperClass. "
                      + "First check for a SuperClass using HasSuperClass.", modelClass.ClassNameBO),
                 exceptionThrown.Message);
        }

        [Test]
        public void Test_SuperClass()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            modelClass.InheritanceSuperClassRelationship = dmInheritanceRelationship;
            DMClass superClass = new DMClass();
            superClass.ClassNameBO = GetRandomString();
            dmInheritanceRelationship.SuperClass = superClass;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IModelClass testSuperClass = ((IModelClass)modelClass).SuperClass;
            //---------------Test Result -----------------------
            Assert.AreSame(dmInheritanceRelationship.SuperClass, testSuperClass);
        }

        [Test]
        public void Test_SuperClass_NullSuperClass_ThrowsException()
        {
            //---------------Set up test pack-------------------
            DMClass modelClass = new DMClass();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                IModelClass testSuperClass = ((IModelClass)modelClass).SuperClass;
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            Assert.AreEqual
                (string.Format
                     ("SuperClass is being called on class '{0}' when the class has no SuperClass. "
                      + "First check for a SuperClass using HasSuperClass.", modelClass.ClassNameBO),
                 exceptionThrown.Message);
        }

        [Test]
        public void Test_AddDefaultIDProp_ShouldAddAnIdPropWithAGuidID()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateSavedDMClass();
            string classNameBO = dmClass.ClassNameBO;
            //---------------Assert Precondition----------------
            Assert.AreEqual(0, dmClass.Properties.Count);
            //---------------Execute Test ----------------------
            dmClass.CreateObjectIdWithDefaultProp();
            //---------------Test Result -----------------------
            Assert.AreEqual(1, dmClass.Properties.Count);
            DMProperty property = dmClass.Properties[0];
            Assert.That(property.PropertyName, Is.EqualTo(classNameBO + "ID"));
            Assert.AreEqual("System.Guid", property.PropertyTypeString);
            Assert.IsNotNull(dmClass.ObjectIdentity);
            Assert.IsTrue(dmClass.ObjectIdentity.IsObjectID.GetValueOrDefault());
            Assert.AreEqual(1, dmClass.ObjectIdentity.Properties.Count);
            Assert.AreSame(property, dmClass.ObjectIdentity.Properties[0]);
            Assert.IsTrue(property.Status.IsNew);
            Assert.IsTrue(dmClass.ObjectIdentity.Status.IsNew);

        }

        [Test]
        public void Test_AddDefaultIDProp_WhenHasID_ShouldDoNothing()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateSavedDMClass();
            dmClass.CreateObjectIdWithDefaultProp();
            DMProperty property = dmClass.Properties[0];
            DMObjectIdentity objectIdentity = dmClass.ObjectIdentity;
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, dmClass.Properties.Count);
            //---------------Execute Test ----------------------
            dmClass.CreateObjectIdWithDefaultProp();
            //---------------Test Result -----------------------
            Assert.AreEqual(1, dmClass.Properties.Count);
            Assert.AreSame(property, dmClass.Properties[0]);
            Assert.AreSame(objectIdentity, dmClass.ObjectIdentity);
        }

        [Test]
        public void Test_HasCompulsoryProperties_False()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateSavedDMClass();
            dmClass.CreateObjectIdWithDefaultProp();
            //---------------Execute Test ----------------------
            bool hasCompulsoryProperties = dmClass.HasCompulsoryProperties;
            //---------------Test Result -----------------------
            Assert.IsFalse(hasCompulsoryProperties);
        }

        [Test]
        public void Test_HasCompulsoryProperties_True()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateSavedDMClass();
            dmClass.CreateObjectIdWithDefaultProp();
            DMProperty property = dmClass.Properties.CreateBusinessObject();
            property.Compulsory = true;
            //---------------Execute Test ----------------------
            bool hasCompulsoryProperties = dmClass.HasCompulsoryProperties;
            //---------------Test Result -----------------------
            Assert.IsTrue(hasCompulsoryProperties);
        }

        [Test]
        public void Test_GetSortOrderProperties_OneProp()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            DMClass dmClass = (DMClass)dmProperty.Class;
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, dmClass.AllProperties.Count);
            //---------------Execute Test ----------------------
            BusinessObjectCollection<DMProperty> sortOrderProperties = dmClass.GetSortOrderProperties();
            //---------------Test Result -----------------------
            Assert.AreEqual(1, sortOrderProperties.Count);
            Assert.AreEqual(dmProperty.PropertyName, dmProperty.SortOrderPropertyName);
        }

        [Test]
        public void Test_GetSortOrderProperties_SingleRelatedClass()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            DMClass dmClass = (DMClass)dmProperty.Class;
            DMClass singleRelatedClass = CreateClassWithOneProp(dmClass.Solution);
            DMProperty singleRelatedClassProp = singleRelatedClass.Properties[0];
            DMClass manyRelatedClass = CreateClassWithOneProp(dmClass.Solution);
            DMRelationship dmRelationship = dmClass.OwnerRelationships.CreateBusinessObject();
            dmRelationship.RelationshipName = TestUtilsShared.GetRandomString();
            dmRelationship.Cardinality = Cardinality.Single;
            dmRelationship.RelatedClass = singleRelatedClass;
            DMRelationship dmRelationshipMany = dmClass.OwnerRelationships.CreateBusinessObject();
            dmRelationshipMany.Cardinality = Cardinality.Multiple;
            dmRelationshipMany.RelatedClass = manyRelatedClass;
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, dmClass.AllProperties.Count);
            Assert.AreEqual(2, dmClass.OwnerRelationships.Count);
            Assert.AreEqual(1, singleRelatedClass.AllProperties.Count);
            Assert.AreEqual(Cardinality.Single, dmRelationship.Cardinality);
            Assert.AreEqual(1, manyRelatedClass.AllProperties.Count);
            Assert.AreEqual(Cardinality.Multiple, dmRelationshipMany.Cardinality);

            //---------------Execute Test ----------------------
            BusinessObjectCollection<DMProperty> sortOrderProperties = dmClass.GetSortOrderProperties();
            //---------------Test Result -----------------------
            Assert.AreEqual(2, sortOrderProperties.Count);
            Assert.AreEqual(dmProperty.PropertyName, dmProperty.SortOrderPropertyName);
            Assert.AreEqual(dmRelationship.RelationshipName + "." + singleRelatedClassProp.PropertyName, singleRelatedClassProp.SortOrderPropertyName);
        }

        [Test]
        public void Test_GetRelationshipName_ShouldReturnRelationshipWithSpecifiedName_WhenRelationshipExists()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            DMClass dmClass = (DMClass)dmProperty.Class;
            DMClass singleRelatedClass = CreateClassWithOneProp(dmClass.Solution);
            DMProperty singleRelatedClassProp = singleRelatedClass.Properties[0];
            DMClass manyRelatedClass = CreateClassWithOneProp(dmClass.Solution);
            DMRelationship dmRelationship = dmClass.OwnerRelationships.CreateBusinessObject();
            string relationshipName = TestUtilsShared.GetRandomString();
            dmRelationship.RelationshipName = relationshipName;
            dmRelationship.Cardinality = Cardinality.Single;
            dmRelationship.RelatedClass = singleRelatedClass;
            DMRelationship dmRelationshipMany = dmClass.OwnerRelationships.CreateBusinessObject();
            dmRelationshipMany.Cardinality = Cardinality.Multiple;
            dmRelationshipMany.RelatedClass = manyRelatedClass;
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, dmClass.OwnerRelationships.Count);
            //---------------Execute Test ----------------------
            IRelationshipDef relationship = dmClass.GetRelationship(relationshipName);
            //---------------Test Result -----------------------
            Assert.IsNotNull(relationship);
        }

        [Test]
        public void Test_GetUniqueViewNameWithSuffix_OneView_Default()
        {
            //---------------Set up test pack-------------------
            string viewName ="default";
            DMClass dmClass = TestUtilsShared.CreateUnsavedValidDMClass();
            UIView uiView = dmClass.UIViews.CreateBusinessObject();
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, dmClass.UIViews.Count);
            Assert.AreEqual(viewName,uiView.ViewName);
            //---------------Execute Test ----------------------
            string uniqueViewName = dmClass.GetUniqueViewNameWithSuffix(uiView.ViewName);
            //---------------Test Result -----------------------
            Assert.AreEqual(viewName, uniqueViewName);
        }

        [Test]
        public void Test_GetUniqueViewNameWithSuffix_TwoView_Default()
        {
            //---------------Set up test pack-------------------
            string viewName ="default";
            DMClass dmClass = TestUtilsShared.CreateUnsavedValidDMClass();
            UIView uiView1 = dmClass.UIViews.CreateBusinessObject();
            UIView uiView2 = dmClass.UIViews.CreateBusinessObject();
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, dmClass.UIViews.Count);
            Assert.AreEqual(viewName,uiView1.ViewName);
            Assert.AreEqual(viewName,uiView1.ViewName);
            //---------------Execute Test ----------------------
            string uniqueViewName = dmClass.GetUniqueViewNameWithSuffix(uiView2.ViewName);
            //---------------Test Result -----------------------
            Assert.AreEqual("default1", uniqueViewName);
        }
        [Test]
        public void Test_GetUniqueViewNameWithSuffix_ThreeView_Default()
        {
            //---------------Set up test pack-------------------
            string viewName ="default";
            DMClass dmClass = TestUtilsShared.CreateUnsavedValidDMClass();
            UIView uiView1 = dmClass.UIViews.CreateBusinessObject();
            uiView1.ViewName = viewName + "8";
            UIView uiView2 = dmClass.UIViews.CreateBusinessObject();
            uiView2.ViewName = viewName + "12";
            UIView uiView3 = dmClass.UIViews.CreateBusinessObject();
            uiView3.ViewName = viewName + "7";
            UIView uiView4 = dmClass.UIViews.CreateBusinessObject();
            //---------------Assert Precondition----------------
            Assert.AreEqual(4, dmClass.UIViews.Count);
            //---------------Execute Test ----------------------
            string uniqueViewName = dmClass.GetUniqueViewNameWithSuffix(viewName);
            //---------------Test Result -----------------------
            Assert.AreEqual("default13", uniqueViewName);
        }
        

        private static DMClass CreateClassWithOneProp(IDMSolution dmSolution)
        {
            DMClass relatedClass = TestUtilsShared.CreateUnsavedValidDMClass(dmSolution);
            TestUtilsShared.CreateUnsavedValidDMProperty(relatedClass);
            return relatedClass;
        }


        #region IClassDef Implementation

        [Test]
        public void Test_PrimaryKeyDef_WhenHasID_ShouldReturnID()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateSavedDMClass();
            dmClass.CreateObjectIdWithDefaultProp();
            DMObjectIdentity identity = dmClass.ObjectIdentity;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(identity);
            Assert.IsTrue(identity.HasProperties, "Should Have properties else it is not and ID");
            //---------------Execute Test ----------------------
            IPrimaryKeyDef primaryKeyDef = dmClass.Properties.ClassDef.PrimaryKeyDef;
            //---------------Test Result -----------------------
            Assert.IsNotNull(primaryKeyDef);
            Assert.AreSame(identity, dmClass.ObjectIdentity);
        }
        [Test]
        public void Test_PrimaryKeyDef_WhenNotHasID_AndNotHasSuperClass_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateSavedDMClass();
            DMObjectIdentity identity = dmClass.ObjectIdentity;
            //---------------Assert Precondition----------------
            Assert.IsNull(identity);
            //---------------Execute Test ----------------------
            IPrimaryKeyDef primaryKeyDef = dmClass.Properties.ClassDef.PrimaryKeyDef;
            //---------------Test Result -----------------------
            Assert.AreEqual(1, primaryKeyDef.Count);
        }
        [Test]
        public void Test_PrimaryKeyDef_WhenNotHasID_AndHasSuperClass_ShouldReturnSuperClassID()
        {
            //---------------Set up test pack-------------------
            DMClass superClass = TestUtilsDMClass.CreateSavedDMClass();
            superClass.CreateObjectIdWithDefaultProp();

            DMProperty property = TestUtilsDMProperty.CreateUnsavedValidDMProperty();
            superClass.Properties.Add(property);
            DMObjectIdentity identity = superClass.ObjectIdentity;
            superClass.Save();
            DMClass dmClass = TestUtilsDMClass.CreateSavedDMClass();

            SetInheritanceRelationship(superClass, property, dmClass);
            //---------------Assert Precondition----------------
            Assert.IsTrue(identity.HasProperties, "Should Have properties else it is not and ID");

            //---------------Execute Test ----------------------
            IPrimaryKeyDef primaryKeyDef = dmClass.Properties.ClassDef.PrimaryKeyDef;
            //---------------Test Result -----------------------
            Assert.IsNotNull(primaryKeyDef);
            Assert.AreSame(identity, dmClass.GetObjectID());
        }

        [Test]
        public void Test_HasRelationshipsWithFK_WhenHasRelationshipWithRelatedBOHasFK_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            FakeDMClass dmClass = GetFakeDMClass();
            DMRelationship relationship = MockRepository.GenerateStub<DMRelationship>(ConstructForFakes.True);
            SetRelatedBOHasFK(relationship, true);
            dmClass.RelationshipsDM.Add(relationship);
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, dmClass.RelationshipsDM.Count);
            Assert.IsTrue(relationship.RelatedBOHasForeignKey);
            //---------------Execute Test ----------------------
            var hasRelationshipsWithFK = dmClass.HasRelationshipsWithRelatedFK;
            //---------------Test Result -----------------------
            Assert.IsTrue(hasRelationshipsWithFK);
        }
        [Test]
        public void Test_HasRelationshipsWithFK_WhenHasRelationshipAndRelatedBOHasFKFalse_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            FakeDMClass dmClass = GetFakeDMClass();
            DMRelationship relationship = MockRepository.GenerateStub<DMRelationship>();
            SetRelatedBOHasFK(relationship, false);
            dmClass.RelationshipsDM.Add(relationship);
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, dmClass.RelationshipsDM.Count);
            Assert.IsFalse(relationship.RelatedBOHasForeignKey);
            //---------------Execute Test ----------------------
            var hasRelationshipsWithFK = dmClass.HasRelationshipsWithRelatedFK;
            //---------------Test Result -----------------------
            Assert.IsFalse(hasRelationshipsWithFK);
        }  
        [Test]
        public void Test_HasRelationshipsWithFK_WhenMultipleRelsOneHasRelatedBOHasFKTrue_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            FakeDMClass dmClass = GetFakeDMClass();
            DMRelationship relationship = MockRepository.GenerateMock<DMRelationship>(ConstructForFakes.True);
            SetRelatedBOHasFK(relationship, true);
            dmClass.RelationshipsDM.Add(relationship);
            dmClass.RelationshipsDM.Add(MockRepository.GenerateMock<DMRelationship>());
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, dmClass.RelationshipsDM.Count);
            Assert.IsTrue(relationship.RelatedBOHasForeignKey);
            //---------------Execute Test ----------------------
            var hasRelationshipsWithFK = dmClass.HasRelationshipsWithRelatedFK;
            //---------------Test Result -----------------------
            Assert.IsTrue(hasRelationshipsWithFK);
        }

        [Test]
        public void Test_HasRelationshipsWithFK_WhenNoRelationship_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            FakeDMClass dmClass = GetFakeDMClass();
            //---------------Assert Precondition----------------
            Assert.AreEqual(0, dmClass.RelationshipsDM.Count);
            //---------------Execute Test ----------------------
            var hasRelationshipsWithFK = dmClass.HasRelationshipsWithRelatedFK;
            //---------------Test Result -----------------------
            Assert.IsFalse(hasRelationshipsWithFK);
        }

        [Test]
        public void Test_RenameClass_WhenMappedTableNull_ShouldRenameDBAndDisplayNameToStandardName()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass
                                  {
                                      ClassNameBO = GetRandomString(),
                                      DisplayName = GetRandomString(),
                                      MappedTableName = GetRandomString()
                                  };
            //---------------Assert Precondition----------------
            Assert.IsNull(dmClass.MappedTable);
            Assert.AreNotEqual(dmClass.ClassNameBO, dmClass.MappedTableName);
            Assert.AreNotEqual(DMClass.GetDisplayNameFromClassName(dmClass.ClassNameBO), dmClass.DisplayName);
            //---------------Execute Test ----------------------
            dmClass.RenameClass();
            //---------------Test Result -----------------------
            Assert.AreEqual(DMClass.GetDisplayNameFromClassName(dmClass.ClassNameBO), dmClass.DisplayName);
            Assert.AreEqual(dmClass.ClassNameBO, dmClass.MappedTableName);
        }
        [Test]
        public void Test_RenameClass_WhenWhenObjectID_WhenPKPropNullMappedDBColumn_ShouldRenamePKPropToClassNameID()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass
                                  {
                                      ClassNameBO = GetRandomString(),
                                  };
            var expectedPKPropName = dmClass.ClassNameBO + "ID";
            var objectIdentity = TestUtilsShared.CreateUnsavedValidObjectIdentityInfo(dmClass);
            var pkProp = objectIdentity.Properties.First();
            //---------------Assert Precondition----------------
            Assert.IsNull(pkProp.MappedDBColumn);
            Assert.AreNotEqual(expectedPKPropName, pkProp.PropertyName);
            Assert.AreNotEqual(DMProperty.GetColumnNameFromPropName(expectedPKPropName), pkProp.MappedDBColumnName);
            Assert.AreNotEqual(DMProperty.GetDisplayNameFromPropertyName(expectedPKPropName), pkProp.DisplayName);
            //---------------Execute Test ----------------------
            dmClass.RenameClass();
            //---------------Test Result -----------------------
            Assert.AreEqual(expectedPKPropName, pkProp.PropertyName);
            Assert.AreEqual(DMProperty.GetColumnNameFromPropName(expectedPKPropName), pkProp.MappedDBColumnName);
            Assert.AreEqual(DMProperty.GetDisplayNameFromPropertyName(expectedPKPropName), pkProp.DisplayName);
        }
        [Test]
        public void Test_RenameClass_WhenGetObjectIDNull_ShouldCreatePKPropAndObjectID()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass
                                  {
                                      ClassNameBO = GetRandomString(),
                                  };
            var expectedPKPropName = dmClass.ClassNameBO + "ID";
            //---------------Assert Precondition----------------
            Assert.IsNull(dmClass.GetObjectID());
            //---------------Execute Test ----------------------
            dmClass.RenameClass();
            //---------------Test Result -----------------------
            Assert.IsNotNull(dmClass.GetObjectID());
            var pkProp = dmClass.GetObjectID().Properties.First();
            Assert.AreEqual(expectedPKPropName, pkProp.PropertyName);
            Assert.AreEqual(DMProperty.GetColumnNameFromPropName(expectedPKPropName), pkProp.MappedDBColumnName);
            Assert.AreEqual(DMProperty.GetDisplayNameFromPropertyName(expectedPKPropName), pkProp.DisplayName);
        }
        [Test]
        public void Test_RenameClass_WhenGetObjectIDNull_AndIsSubClass_ShouldNotCreateObjectID()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass
                                  {
                                      ClassNameBO = GetRandomString(),
                                  };
            dmClass.InheritanceSuperClassRelationship = new DMInheritanceRelationship();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmClass.InheritanceSuperClassRelationship);
            Assert.IsNull(dmClass.ObjectIdentity);
            //---------------Execute Test ----------------------
            dmClass.RenameClass();
            //---------------Test Result -----------------------
            Assert.IsNull(dmClass.ObjectIdentity);
        }

        private static FakeDMClass GetFakeDMClass()
        {
            var dmClass = new FakeDMClass();
            dmClass.SetRelationshipsDM(new FakeBusinessObjectCollection<DMRelationship>());
            return dmClass;
        }

        private static void SetRelatedBOHasFK(DMRelationship relationship, bool relatedBOHasFK)
        {
            relationship.Stub(dmRelationship => dmRelationship.RelatedBOHasForeignKey).Return(relatedBOHasFK);
        }

        private static void SetInheritanceRelationship(DMClass superClass, DMProperty property, DMClass dmClass)
        {
            DMInheritanceRelationship relationship = new DMInheritanceRelationship();
            relationship.SuperClass = superClass;
            relationship.SubClass = dmClass;
            relationship.InheritanceType = ORMapping.SingleTableInheritance;
            relationship.Discriminator = property.PropertyName;
            relationship.Save();
        }

        #endregion



        private static DMRelationship CreateDmRelationship(DMClass dmClass)
        {
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.RelationshipName =  GetRandomString();
            dmClass.OwnerRelationships.Add(dmRelationship);
            return dmRelationship;
        }
#pragma warning restore 168
    }
}